numpy.ma.atleast_3d#

ma.atleast_3d(*arys)[源代码]#

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

参数:
arys1, arys2, …array_like

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

返回:
res1, res2, …ndarray

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

另请参阅

atleast_1d, atleast_2d

备注

该函数应用于 _data_mask(如果存在)。

示例

>>> import numpy as np
>>> 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)