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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

mstar1992   2021-04-02 我要评论

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

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]])

以上这篇谈一谈数组拼接tf.concat()和np.concatenate()的区别就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们