本文主要是介绍Numpy --expand_dims,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这是别人总结好的点击打开链接
下面是我自己做的一些测试
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.shape)
print(a)
print('\n')b = np.expand_dims(a, 0)
print(b)
print(b.shape)
print('\n')
c = np.expand_dims(a, 1)
print(c)
print(c.shape)
print('\n')
d = np.expand_dims(a, 2)
print(d)
print(d.shape)
print('\n')
e = np.expand_dims(a, 3)
print(e)
print(e.shape)
结果:
(2, 3)
[[1 2 3]
[4 5 6]]
[[[1 2 3]
[4 5 6]]]
(1, 2, 3)
[[[1 2 3]]
[[4 5 6]]]
(2, 1, 3)
[[[1]
[2]
[3]]
[[4]
[5]
[6]]]
(2, 3, 1)
[[[1]
[2]
[3]]
[[4]
[5]
[6]]]
(2, 3, 1)
这篇关于Numpy --expand_dims的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!