mindspore.numpy.atleast_3d

mindspore.numpy.atleast_3d(*arys)[源代码]

Reshapes inputs as arrays with at least three dimensions.

说明

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

参数

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

返回

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).

异常

TypeError – If the input is not a tensor.

Supported Platforms:

Ascend GPU CPU

样例

>>> 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+00], [1.00000000e+00], [1.00000000e+00]],
    [[1.00000000e+00], [1.00000000e+00], [1.00000000e+00]]]),
    Tensor(shape=[1, 1, 1], dtype=Float32, value= [[[1.00000000e+00]]]),
    Tensor(shape=[1, 5, 1], dtype=Float32,
    value= [[[1.00000000e+00], [1.00000000e+00], [1.00000000e+00],
    [1.00000000e+00], [1.00000000e+00]]])]