mindspore.numpy.atleast_1d
- mindspore.numpy.atleast_1d(*arys)[source]
Converts inputs to arrays with at least one dimension.
Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved.
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 >= 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_1d(a, b, c) >>> print(output) [Tensor(shape=[2, 3], dtype=Float32, value= [[1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]), Tensor(shape=[1], dtype=Float32, value= [1.00000000e+00]), Tensor(shape=[5], dtype=Float32, value= [1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])]