据我所知,您无法像使用 NumPy 等更高级的库那样在一个命令中真正做到这一点。
如果你真的想使用 TF 函数,我可以推荐一些类似的函数:
x = tf.Variable([
[1,2,3,1],
[0,0,0,0],
[1,3,5,7],
[0,0,0,0],
[3,5,7,8]])
y = tf.Variable([0,0,0,0])
condition = tf.equal(x, y)
indices = tf.where(condition)
这将导致以下结果:
[[1 0]
[1 1]
[1 2]
[1 3]
[3 0]
[3 1]
[3 2]
[3 3]]
或者,如果您只想获取零线,则可以使用以下命令:
row_wise_sum = tf.reduce_sum(tf.abs(x),1)
select_zero_sum = tf.where(tf.equal(row_wise_sum,0))
with tf.Session() as sess:
tf.global_variables_initializer().run()
print(sess.run(select_zero_sum))
结果是:
[[1]
[3]]