mindspore.numpy.atleast_3d

mindspore.numpy.atleast_3d(*arys)[source]

Reshapes inputs as arrays with at least three dimensions.

Note

In graph mode, returns a tuple of tensor instead of a list of tensors.

Parameters

*arys (Tensor) – one or more input tensors.

Returns

Tensor, or list of tensors, each with a.ndim >= 3. For example, a 1-D array of shape (N,) becomes a tensor of shape (1, N, 1), and a 2-D array of shape (M, N) becomes a tensor of shape (M, N, 1).

Raises

TypeError – if the input is not a tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> a = np.ones((2, 3))
>>> b = np.ones(())
>>> c = np.ones(5)
>>> output = np.atleast_3d(a, b, c)
>>> print(output)
    [Tensor(shape=[2, 3, 1], dtype=Float32, value=
    [[[1.00000000e+000], [1.00000000e+000], [1.00000000e+000]],
    [[1.00000000e+000], [1.00000000e+000], [1.00000000e+000]]]),
    Tensor(shape=[1, 1, 1], dtype=Float32, value= [[[1.00000000e+000]]]),
    Tensor(shape=[1, 5, 1], dtype=Float32,
    value= [[[1.00000000e+000], [1.00000000e+000], [1.00000000e+000],
    [1.00000000e+000], [1.00000000e+000]]])]