numpy.atleast_3d

numpy.atleast_3d(*arys)

View inputs as arrays with at least three dimensions.

Parameters:

array1, array2, ... : array_like

One or more array-like sequences. Non-array inputs are converted to arrays. Arrays that already have three or more dimensions are preserved.

Returns:

res1, res2, ... : ndarray

An array, or tuple of arrays, each with a.ndim >= 3. Copies are avoided where possible, and views with three or more dimensions are returned. For example, a one-dimensional array of shape N becomes a view of shape (1, N, 1). An (M, N) array becomes a view of shape (N, M, 1).

Examples

>>> numpy.atleast_3d(3.0)
array([[[ 3.]]])
>>> x = numpy.arange(3.0)
>>> numpy.atleast_3d(x).shape
(1, 3, 1)
>>> x = numpy.arange(12.0).reshape(4,3)
>>> numpy.atleast_3d(x).shape
(4, 3, 1)
>>> numpy.atleast_3d(x).base is x
True
>>> for arr in np.atleast_3d(1, [1, 2], [[1, 2]]): print arr, "\n"
...
[[[1]]]
[[[1]
[2]]]
[[[1]
[2]]]

Previous topic

numpy.atleast_2d

Next topic

numpy.broadcast

This Page

Quick search