[−][src]Enum ndarray::SliceOrIndex
A slice (range with step) or an index.
See also the s![]
macro for a convenient way to create a
&SliceInfo<[SliceOrIndex; n], D>
.
Examples
SliceOrIndex::Index(a)
is the index a
. It can also be created with
SliceOrIndex::from(a)
. The Python equivalent is [a]
. The macro
equivalent is s![a]
.
SliceOrIndex::Slice { start: 0, end: None, step: 1 }
is the full range of
an axis. It can also be created with SliceOrIndex::from(..)
. The Python
equivalent is [:]
. The macro equivalent is s![..]
.
SliceOrIndex::Slice { start: a, end: Some(b), step: 2 }
is every second
element from a
until b
. It can also be created with
SliceOrIndex::from(a..b).step_by(2)
. The Python equivalent is [a:b:2]
.
The macro equivalent is s![a..b;2]
.
SliceOrIndex::Slice { start: a, end: None, step: -1 }
is every element,
from a
until the end, in reverse order. It can also be created with
SliceOrIndex::from(a..).step_by(-1)
. The Python equivalent is [a::-1]
.
The macro equivalent is s![a..;-1]
.
Variants
A range with step size. end
is an exclusive index. Negative begin
or end
indexes are counted from the back of the axis. If end
is
None
, the slice extends to the end of the axis.
Index(isize)
A single index.
Methods
impl SliceOrIndex
[src][−]
pub fn is_slice(&self) -> bool
[src][−]
Returns true
if self
is a Slice
value.
pub fn is_index(&self) -> bool
[src][−]
Returns true
if self
is an Index
value.
pub fn step_by(self, step: isize) -> Self
[src][−]
Returns a new SliceOrIndex
with the given step size (multiplied with
the previous step size).
step
must be nonzero.
(This method checks with a debug assertion that step
is not zero.)
Trait Implementations
impl Clone for SliceOrIndex
[src][+]
impl Copy for SliceOrIndex
[src]
impl Debug for SliceOrIndex
[src][+]
impl Display for SliceOrIndex
[src][+]
impl Eq for SliceOrIndex
[src]
impl From<Range<i32>> for SliceOrIndex
[src][+]
impl From<Range<isize>> for SliceOrIndex
[src][+]
impl From<Range<usize>> for SliceOrIndex
[src][+]
impl From<RangeFrom<i32>> for SliceOrIndex
[src][+]
impl From<RangeFrom<isize>> for SliceOrIndex
[src][+]
impl From<RangeFrom<usize>> for SliceOrIndex
[src][+]
impl From<RangeFull> for SliceOrIndex
[src][+]
impl From<RangeInclusive<i32>> for SliceOrIndex
[src][+]
impl From<RangeInclusive<isize>> for SliceOrIndex
[src][+]
impl From<RangeInclusive<usize>> for SliceOrIndex
[src][+]
impl From<RangeTo<i32>> for SliceOrIndex
[src][+]
impl From<RangeTo<isize>> for SliceOrIndex
[src][+]
impl From<RangeTo<usize>> for SliceOrIndex
[src][+]
impl From<RangeToInclusive<i32>> for SliceOrIndex
[src][+]
impl From<RangeToInclusive<isize>> for SliceOrIndex
[src][+]
impl From<RangeToInclusive<usize>> for SliceOrIndex
[src][+]
impl From<Slice> for SliceOrIndex
[src][+]
impl From<i32> for SliceOrIndex
[src][+]
impl From<isize> for SliceOrIndex
[src][+]
impl From<usize> for SliceOrIndex
[src][+]
impl Hash for SliceOrIndex
[src][+]
impl PartialEq<SliceOrIndex> for SliceOrIndex
[src][+]
impl StructuralEq for SliceOrIndex
[src]
impl StructuralPartialEq for SliceOrIndex
[src]
Auto Trait Implementations
impl RefUnwindSafe for SliceOrIndex
impl Send for SliceOrIndex
impl Sync for SliceOrIndex
impl Unpin for SliceOrIndex
impl UnwindSafe for SliceOrIndex
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src][+]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,