我要执行以下操作。给定张量
m = ([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
如何实现从m中删除值[2,2,2]的向量?
您可以这样做:
import tensorflow as tf
def remove_row(m, q):
# Assumes m is 2D
mask = tf.math.reduce_any(tf.not_equal(m, q), axis=-1)
return tf.boolean_mask(m, mask)
# Test
m = tf.constant([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
q = tf.constant([2, 2, 2])
tf.print(remove_row(m, q))
# [[1 1 1]
# [3 3 3]]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句