mlx.core.slice

目录

mlx.core.slice#

slice(a: array, start_indices: array, axes: Sequence[int], slice_size: Sequence[int], *, stream: None | Stream | Device = None) array#

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

参数:
  • a (array) – 输入数组

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

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

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

返回:

切片后的输出数组。

返回类型:

array

示例

>>> 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)