numpy.ma.atleast_3d#
- ma.atleast_3d = <numpy.ma.extras._fromnxfunction_allargs object>#
將輸入視為至少三維的陣列。
- 參數:
- arys1, arys2, …類陣列
一個或多個類陣列序列。非陣列輸入會被轉換成陣列。已具有三個或更多維度的陣列會被保留。
- 回傳值:
- 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)