numpy.atleast_3d

numpy.atleast_3d(*arys)[源代码]

将输入视为至少具有三维的数组。

参数
芳基1,芳基2,…array_like

一个或多个类似数组的序列。非数组输入转换为数组。已具有三个或更多维度的数组将被保留。

返回
RES1,RES2,…恩达雷

数组或数组列表,每个数组 a.ndim >= 3 . 尽可能避免复制,并返回具有三个或更多维度的视图。例如,一维形状数组 (N,) 成为形状视图 (1, N, 1) 和二维形状数组 (M, N) 成为形状视图 (M, N, 1) .

实例

>>> np.atleast_3d(3.0)
array([[[3.]]])
>>> x = np.arange(3.0)
>>> np.atleast_3d(x).shape
(1, 3, 1)
>>> x = np.arange(12.0).reshape(4,3)
>>> np.atleast_3d(x).shape
(4, 3, 1)
>>> np.atleast_3d(x).base is x.base  # x is a reshape, so not base itself
True
>>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
...     print(arr, arr.shape) 
...
[[[1]
  [2]]] (1, 2, 1)
[[[1]
  [2]]] (1, 2, 1)
[[[1 2]]] (1, 1, 2)