mindspore.ops.chunk

mindspore.ops.chunk(input, chunks, axis=0)[源代码]

沿着指定轴 axis 将输入Tensor切分成 chunks 个sub-tensor。

说明

此函数返回的数量可能小于通过 chunks 指定的数量!

参数:
  • input (Tensor) - 被切分的Tensor。

  • chunks (int) - 要切分的sub-tensor数量。

  • axis (int,可选) - 指定需要分割的维度。默认值:0。

返回:

tuple[Tensor]。

异常:
  • TypeError - input 不是Tensor。

  • TypeError - axis 不是int类型。

  • TypeError - chunks 不是int。

  • ValueError - 参数 axis 超出 \([-input.ndim, input.ndim)\) 范围。

  • ValueError - 参数 chunks 不是正数。

支持平台:

Ascend GPU CPU

样例:

>>> input_x = np.arange(9).astype("float32")
>>> output = ops.chunk(Tensor(input_x), 3)
>>> print(output)
(Tensor(shape=[3], dtype=Float32, value= [ 0.00000000e+00,  1.00000000e+00,  2.00000000e+00]),
 Tensor(shape=[3], dtype=Float32, value= [ 3.00000000e+00,  4.00000000e+00,  5.00000000e+00]),
 Tensor(shape=[3], dtype=Float32, value= [ 6.00000000e+00,  7.00000000e+00,  8.00000000e+00]))