【发布时间】:2018-07-30 07:23:06
【问题描述】:
我有以下使用numpy.where的操作:
mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.int32)
index = np.array([[1,0,0],[0,1,0],[0,0,1]])
mat[np.where(index>0)] = 100
print(mat)
如何在TensorFlow中实现等价物?
mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.int32)
index = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
tf_mat = tf.constant(mat)
tf_index = tf.constant(index)
indi = tf.where(tf_index>0)
tf_mat[indi] = -1 <===== not allowed
【问题讨论】:
-
np.where()在这里不需要:mat[index > 0] = 100 -
不管怎样,在tensorflow中如何满足相同的意图?
标签: python numpy tensorflow