mars.tensor.split#

mars.tensor.split(ary, indices_or_sections, axis=0)[来源]#

将张量拆分为多个子张量。

Parameters
  • ary (张量) – 要被划分为子张量的张量。

  • indices_or_sections (int1-D 张量) –

    如果 indices_or_sections 是一个整数 N,则数组将在 axis 上被划分为 N 个相等的张量。如果这样的分割不可能,将引发错误。

    如果 indices_or_sections 是一个排序整数的 1-D 张量,则条目指示数组在 axis 上的分割位置。例如,[2, 3]axis=0 时将导致

    • ary[:2]

    • ary[2:3]

    • ary[3:]

    如果索引超出张量在 axis 上的维度,将相应地返回一个空的子张量。

  • axis (int, 可选) – 切分的轴,默认为 0。

Returns

子张量 – 一组子张量。

Return type

list 的张量

Raises

ValueError – 如果 indices_or_sections 被给定为一个整数,但 划分并没有导致等分。

另请参阅

array_split

将一个张量分割成多个大小相等或近似相等的子张量。如果无法进行等分,则不会引发异常。

hsplit

水平(按列)将其拆分为多个子数组。

vsplit

将张量垂直(按行)拆分为多个子张量。

dsplit

沿着第3个轴(深度)将张量分割成多个子张量。

concatenate

沿着现有轴连接一系列张量。

stack

沿着新的轴连接张量序列。

hstack

按顺序水平(按列)堆叠张量。

vstack

垂直(按行)顺序堆叠张量。

dstack

沿着第三个维度按顺序堆叠张量。

示例

>>> import mars.tensor as mt
>>> x = mt.arange(9.0)
>>> mt.split(x, 3).execute()
[array([ 0.,  1.,  2.]), array([ 3.,  4.,  5.]), array([ 6.,  7.,  8.])]
>>> x = mt.arange(8.0)
>>> mt.split(x, [3, 5, 6, 10]).execute()
[array([ 0.,  1.,  2.]),
 array([ 3.,  4.]),
 array([ 5.]),
 array([ 6.,  7.]),
 array([], dtype=float64)]