用于扩展数组的形状
import numpy as np
In [12]:
a = np.array([[[1,2,3],[4,5,6]]])
a.shape
Out[12]:
(1, 2, 3)
np.expand_dims(a, axis=0)表示在0位置添加数据,转换结果如下:
In [13]:
b = np.expand_dims(a, axis=0)
b
Out[13]:
array([[[[1, 2, 3],
[4, 5, 6]]]])
In [14]:
b.shape
Out[14]:
(1, 1, 2, 3)