import numpy as np

a = np.array([[1,2],[3,5]])

x = np.expand_dims(a, axis=0)
y = np.expand_dims(a, axis=1)
z = np.expand_dims(a, axis=2)
print(a.shape)
print(x.shape)
print(y.shape)
print(z.shape)

输出结果:

np.expand_dims_python

x:

np.expand_dims_python_02

y:

np.expand_dims_python_03

z:

np.expand_dims_python_04

参考知乎​​https://www.zhihu.com/question/265545749​

np.expand_dims_python_05


np.expand_dims_python_06

np.expand_dims_python_07

np.expand_dims_python_08

np.expand_dims_python_09

参考:

​https://blog.csdn.net/qq_40643699/article/details/107985401​