maxframe.tensor.split#

maxframe.tensor.split(ary, indices_or_sections, axis=0)[源代码]#

将一个张量分割成多个子张量。

参数:
  • ary (Tensor) -- 要分割成子张量的张量。

  • indices_or_sections (int or 1-D tensor) -- 如果 indices_or_sections 是一个整数 N,则数组将沿着 axis 被分割成 N 个相等的张量。如果这样的分割不可行,则会引发一个错误。如果 indices_or_sections 是一个排序的 1 维整数张量,则条目表示数组沿 axis 的分割位置。例如,对于 axis=0[2, 3] 会得到: - ary[:2] - ary[2:3] - ary[3:] 如果索引超过沿 axis 的张量维度,则相应地返回一个空的子张量。

  • axis (int, optional) -- 分割的轴,默认为 0。

返回:

子张量 -- 子张量的列表。

返回类型:

list of Tensors

抛出:

ValueError -- 如果 indices_or_sections 被指定为整数,但分割不能实现等分。

参见

array_split

将张量分割成多个大小相等或接近相等的子张量。如果无法实现等分,不会引发异常。

hsplit

将张量水平(按列)分割成多个子数组。

vsplit

将张量垂直(按行)分割成多个子张量。

dsplit

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

concatenate

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

stack

沿着新轴连接一系列张量。

:py:obj:hstack

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

:py:obj:vstack

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

:py:obj:dstack

按顺序深度堆叠张量(沿第三维度)。

示例

>>> import maxframe.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)]