mindspore.numpy.array_split
- mindspore.numpy.array_split(x, indices_or_sections, axis=0)[源代码]
- 将一个Tensor切分为多个Sub-Tensors。 - 说明 - 目前, - array_split仅支持CPU上的- mindspore.float32。- np.split和- np.array_split之间的唯一区别是,- np.array_split允许- indices _or_sections是一个不用等分- axis的整数。对于长度为l的Tensor,其应当被分割成n个部分,返回的子数组中一部分子数组shape为 \(l//n+1\) ,剩余子数组shape为 \(l//n\) 。- 参数:
- x (Tensor) - 待切分的Tensor。 
- indices_or_sections (Union[int, tuple(int), list(int)]) - 如果是整数 \(N\) ,Tensor将沿指定的轴被拆分成 \(N\) 个子张量。如果是tuple(int)、list(int)或排序后的整数序列,则这些条目表示在指定轴上的拆分位置。例如,给定 \([2,3]\) 在 \(axis=0\) 上拆分,则结果将是三个Sub-Tensors,为 \(x[:2]\) , \(x[2:3]\) , \(x[3:]\) 。如果某个索引超出了指定轴的维度,相应地将返回一个空子数组。 
- axis (int) - 要沿其切分的轴。默认值: - 0。
 
- 返回:
- Sub-Tensors列表。 
- 异常:
- TypeError - 如果参数 - indices_or_sections不是整数、tuple(int)或list(int),或者参数- axis不是整数。
- ValueError - 如果参数 - axis超出 \([-x.ndim,x.ndim)\) 的范围。
 
- 支持平台:
- Ascend- GPU- CPU
 - 样例: - >>> import mindspore.numpy as np >>> input_x = np.arange(9).astype("float32") >>> output = np.array_split(input_x, 4) >>> print(output) (Tensor(shape=[3], dtype=Float32, value= [ 0.00000000e+00, 1.00000000e+00, 2.00000000e+00]), Tensor(shape=[2], dtype=Float32, value= [ 3.00000000e+00, 4.00000000e+00]), Tensor(shape=[2], dtype=Float32, value= [ 5.00000000e+00, 6.00000000e+00]), Tensor(shape=[2], dtype=Float32, value= [ 7.00000000e+00, 8.00000000e+00]))