mindspore.ops.chunk

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

沿着指定轴将输入tensor切分成多个子tensor。

说明

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

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

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

  • axis (int,可选) - 指定轴。默认 0

返回:

由tensor组成的tuple。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> input = mindspore.ops.arange(0, 9, dtype=mindspore.float32)
>>> output = mindspore.ops.chunk(input, 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]))