mars.tensor.atleast_1d

mars.tensor.atleast_1d(*tensors)[源代码]

Convert inputs to tensors with at least one dimension.

Scalar inputs are converted to 1-dimensional tensors, whilst higher-dimensional inputs are preserved.

参数
  • tensors1 (array_like) – One or more input tensors.

  • tensors2 (array_like) – One or more input tensors.

  • ... (array_like) – One or more input tensors.

返回

ret – An tensor, or list of tensors, each with a.ndim >= 1. Copies are made only if necessary.

返回类型

Tensor

实际案例

>>> import mars.tensor as mt
>>> mt.atleast_1d(1.0).execute()
array([ 1.])
>>> x = mt.arange(9.0).reshape(3,3)
>>> mt.atleast_1d(x).execute()
array([[ 0.,  1.,  2.],
       [ 3.,  4.,  5.],
       [ 6.,  7.,  8.]])
>>> mt.atleast_1d(x) is x
True
>>> mt.atleast_1d(1, [3, 4]).execute()
[array([1]), array([3, 4])]