ma.
atleast_3d
将输入视为至少具有三维的数组。
一个或多个类似数组的序列。非数组输入转换为数组。已具有三个或更多维度的数组将被保留。
数组或数组列表,每个数组 a.ndim >= 3 . 尽可能避免复制,并返回具有三个或更多维度的视图。例如,一维形状数组 (N,) 成为形状视图 (1, N, 1) 和二维形状数组 (M, N) 成为形状视图 (M, N, 1) .
a.ndim >= 3
(N,)
(1, N, 1)
(M, N)
(M, N, 1)
参见
atleast_1d
atleast_2d
笔记
此函数同时应用于数据和掩码(如果有)。
实例
>>> 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)