mlx.core.slice

目录

mlx.core.slice#

切片(a 数组, 起始索引 数组, 坐标轴 序列[int], 切片大小 序列[int], *, None | Stream | Device = ) 数组#

从输入数组中提取一个子数组。

Parameters
  • a (array) – 输入数组

  • start_indices (array) – 切片开始的索引位置。

  • axes (tuple(int)) – 对应于start_indices中索引的轴。

  • slice_size (tuple(int)) – 切片的大小。

Returns

切片后的输出数组。

Return type

数组

示例

>>> a = mx.array([[1, 2, 3], [4, 5, 6]])
>>> mx.slice(a, start_indices=mx.array(1), axes=(0,), slice_size=(1, 2))
array([[4, 5]], dtype=int32)
>>>
>>> mx.slice(a, start_indices=mx.array(1), axes=(1,), slice_size=(2, 1))
array([[2],
       [5]], dtype=int32)