网络编程
位置:首页>> 网络编程>> 网络编程>> 谈一谈数组拼接tf.concat()和np.concatenate()的区别

谈一谈数组拼接tf.concat()和np.concatenate()的区别

作者:mstar1992  发布时间:2023-01-19 22:15:36 

标签:数组拼接,tf.concat,np.concatenate

废话不多说啦,直接看代码吧!

tf.concat


t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat(0, [t1, t2]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]

# tensor t3 with shape [2, 3]
# tensor t4 with shape [2, 3]
tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3]
tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6]

numpy.concatenate


a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0)
array([[1, 2],
 [3, 4],
 [5, 6]])
np.concatenate((a, b.T), axis=1)
array([[1, 2, 5],
 [3, 4, 6]])

来源:https://blog.csdn.net/u013713117/article/details/54587555

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com