numpy.atleast_3d#
- numpy.atleast_3d(*arys)[source]#
將輸入視為至少三維的陣列。
- 參數:
- arys1、arys2、…array_like
一個或多個類陣列序列。非陣列輸入會轉換為陣列。已具有三個或更多維度的陣列會被保留。
- 回傳值:
- res1、res2、…ndarray
一個陣列或陣列元組,每個陣列的維度
a.ndim >= 3
。盡可能避免複製,並回傳具有三個或更多維度的視圖。例如,形狀為(N,)
的一維陣列會變成形狀為(1, N, 1)
的視圖,而形狀為(M, N)
的二維陣列會變成形狀為(M, N, 1)
的視圖。
另請參閱
範例
>>> 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)