numpy.ma.atleast_3d#
- ma.atleast_3d = <numpy.ma.extras._fromnxfunction_allargs object>#
将输入视为至少具有三个维度的数组.
- 参数:
- arys1, arys2, …array_like
一个或多个类数组序列.非数组输入被转换为数组.已经具有三个或多个维度的数组将被保留.
- 返回:
- res1, res2, …ndarray
一个数组,或数组的元组,每个数组的
a.ndim >= 3. 尽可能避免复制,并返回具有三个或多个维度的视图. 例如,形状为(N,)的一维数组变为形状为(1, N, 1)的视图,而形状为(M, N)的二维数组变为形状为(M, N, 1)的视图.
参见
注释
该函数同时应用于 _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)