mars.tensor.atleast_3d#

mars.tensor.atleast_3d(*tensors)[来源]#

将输入视为至少三维的张量。

Parameters
  • tensors1 (array_like) – 一个或多个张量状序列。 非张量输入会被转换为张量。 已经具有三个或更多维度的张量将被保留。

  • tensors2 (array_like) – 一个或多个类似张量的序列。非张量输入会被转换为张量。已经具有三维或更多维度的张量会被保留。

  • ... (array_like) – 一个或多个类张量的序列。 非张量输入会被转换为张量。 具有三维或更多维度的张量将被保留。

Returns

res1, res2, … – 一个张量,或多个张量的列表,每个张量的 a.ndim >= 3。 尽可能避免复制,并返回具有三个或更多维度的视图。 例如,形状为 (N,) 的 1-D 张量变为形状为 (1, N, 1) 的视图,形状为 (M, N) 的 2-D 张量变为形状为 (M, N, 1) 的视图。

Return type

张量

另请参阅

atleast_1d, atleast_2d

示例

>>> import mars.tensor as mt
>>> mt.atleast_3d(3.0).execute()
array([[[ 3.]]])
>>> x = mt.arange(3.0)
>>> mt.atleast_3d(x).shape
(1, 3, 1)
>>> x = mt.arange(12.0).reshape(4,3)
>>> mt.atleast_3d(x).shape
(4, 3, 1)
>>> for arr in mt.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]).execute():
...     print(arr, arr.shape)
...
[[[1]
  [2]]] (1, 2, 1)
[[[1]
  [2]]] (1, 2, 1)
[[[1 2]]] (1, 1, 2)