我想知道如何从张量中的矩阵中删除元素。
a = tf.Variable(initial_value=[[0, 0, 0, 0],[2, 2, 2, 2],[1, 1, 1, 1]])
b = tf....(a)
#desired output of b, if I want to remove the second element in dim 1 of "a"
[[0, 0, 0, 0],[1, 1, 1, 1]]
#desired output of b, if I want to remove the last element in dim 1 of "a"
[[0, 0, 0, 0],[2, 2, 2, 2]]
答案 0 :(得分:0)
切片然后堆叠
a = tf.Variable(initial_value=[[0, 0, 0, 0],[2, 2, 2, 2],[1, 1, 1, 1]])
b = tf.stack([a[0], a[2]]) #[[0, 0, 0, 0],[1, 1, 1, 1]]
c = tf.stack([a[0], a[1]]) #[[0, 0, 0, 0],[2, 2, 2, 2]]