tf.where()
import tensorflow as tf
import numpy as np
a = np.array([[1,1,1,1,0,0,0],
[1,1,1,1,0,0,0]])
aa = np.array([[1,1,1,1,1,0,0],
[1,1,0,1,0,0,0]])
d = tf.equal(a,aa)
c=tf.where(d)
with tf.Session() as sess:
pp = sess.run(d)
qq = sess.run(c)
print(pp)
print(qq)
tf.gather_nd()
import tensorflow as tf
import numpy as np
a = np.array([[1, 1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0]])
aa = np.array([[1, 1, 1, 1, 1, 0, 0],
[1, 1, 0, 1, 0, 0, 0]])
c = tf.gather_nd(a,[[0,1],[1,2]])
with tf.Session() as sess:
aaa = sess.run(c)
print(aaa)
numpy.stack(arrays, axis=0)
沿着新轴连接数组的序列。
axis参数指定新轴在结果尺寸中的索引。例如,如果axis=0,它将是第一个维度,如果axis=-1,它将是最后一个维度。
参数: 数组:array_like的序列每个数组必须具有相同的形状。axis:int,可选输入数组沿其堆叠的结果数组中的轴。
返回: 堆叠:ndarray堆叠数组比输入数组多一个维。
>>> a = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
>>> b = np.array([[4, 5, 6], [4, 5, 6], [4, 5, 6]])
>>> a.shape
(3, 3)
>>> b.shape
(3, 3)
>>> np.stack((a, b), axis=0).shape
(2, 3, 3)
>>> np.stack((a, b), axis=1).shape
(3, 2, 3)
>>> np.stack((a, b), axis=2).shape
(3, 3, 2)
Python numpy.transpose
A.transpose((0,1,2)) #保持A不变
A.transpose((1,0,2)) #将 0轴 和 1轴 交换