atleast_2d

gala.util.atleast_2d(*arys, **kwargs)[source]

View inputs as arrays with at least two dimensions.

Parameters
arys1, arys2, …array_like

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

insert_axisint (optional)

Where to create a new axis if input array(s) have <2 dim.

Returns
res, res2, …ndarray

An array, or tuple of arrays, each with a.ndim >= 2. Copies are avoided where possible, and views with two or more dimensions are returned.

Examples

>>> atleast_2d(3.0) # doctest: +FLOAT_CMP
array([[3.]])
>>> x = np.arange(3.0)
>>> atleast_2d(x) # doctest: +FLOAT_CMP
array([[0., 1., 2.]])
>>> atleast_2d(x, insert_axis=-1) # doctest: +FLOAT_CMP
array([[0.],
       [1.],
       [2.]])
>>> atleast_2d(x).base is x
True
>>> atleast_2d(1, [1, 2], [[1, 2]])
[array([[1]]), array([[1, 2]]), array([[1, 2]])]