Comment on page
tensor.slice
fn slice(self: @Tensor<T>, starts: Span<usize>, ends: Span<usize>, axes: Option<Span<usize>>, steps: Option<Span<usize>>) -> Tensor<usize>;
Produces a slice of the input tensor along multiple axes.
self
(@Tensor<T>
) - Tensor of data to extract slices from.starts
(Span) - 1-D tensor of starting indices of corresponding axis inaxes
ends
(Span) - 1-D tensor of ending indices (exclusive) of corresponding axis inaxes
axes
(Option<Span>) - 1-D tensor of axes thatstarts
andends
apply to.steps
(Option<Span>) - 1-D tensor of slice step of corresponding axis inaxes
.
- Panics if the length of starts is not equal to the length of ends.
- Panics if the length of starts is not equal to the length of axes.
- Panics if the length of starts is not equal to the length of steps.
A new
Tensor<T>
slice of the input tensor.use array::{ArrayTrait, SpanTrait};
use orion::operators::tensor::{TensorTrait, Tensor, U32Tensor};
fn slice_example() -> Tensor<u32> {
let tensor = TensorTrait::<u32>::new(
shape: array![2, 4].span(),
data: array![0, 1, 2, 3, 4, 5, 6, 7].span(),
);
return tensor.slice(
starts: array![0, 2].span(),
ends: array![2, 4].span(),
axis: Option::None(()),
steps: Option::Some(array![1, 1].span())
);
}
>>> [[2 3]
[6 7]]
Last modified 1mo ago