Type Definition ndarray::ArrayView
[−]
[src]
type ArrayView<'a, A, D> = ArrayBase<ViewRepr<&'a A>, D>;
A read-only array view.
An array view represents an array or a part of it, created from an iterator, subview or slice of an array.
The ArrayView<'a, A, D>
is parameterized by 'a
for the scope of the
borrow, A
for the element type and D
for the dimensionality.
Array views have all the methods of an array (see ArrayBase
).
See also ArrayViewMut
.
Methods
impl<'a, A, D> ArrayView<'a, A, D> where
D: Dimension,
[src]
D: Dimension,
Methods for read-only array views.
fn from_shape<Sh>(shape: Sh, xs: &'a [A]) -> Result<Self, ShapeError> where
Sh: Into<StrideShape<D>>,
Sh: Into<StrideShape<D>>,
Create a read-only array view borrowing its data from a slice.
Checks whether shape
are compatible with the slice's
length, returning an Err
if not compatible.
use ndarray::ArrayView; use ndarray::arr3; use ndarray::ShapeBuilder; let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; let a = ArrayView::from_shape((2, 3, 2).strides((1, 4, 2)), &s).unwrap(); assert!( a == arr3(&[[[0, 2], [4, 6], [8, 10]], [[1, 3], [5, 7], [9, 11]]]) ); assert!(a.strides() == &[1, 4, 2]);
unsafe fn from_shape_ptr<Sh>(shape: Sh, ptr: *const A) -> Self where
Sh: Into<StrideShape<D>>,
Sh: Into<StrideShape<D>>,
Create an ArrayView<A, D>
from shape information and a
raw pointer to the elements.
Unsafe because caller is responsible for ensuring that the pointer is valid, not mutably aliased and coherent with the dimension and stride information.
fn split_at(self, axis: Axis, index: Ix) -> (Self, Self)
Split the array view along axis
and return one view strictly before the
split and one view after the split.
Panics if axis
or index
is out of bounds.
Below, an illustration of .split_at(Axis(2), 2)
on
an array with shape 3 × 5 × 5.
fn into_slice(&self) -> Option<&'a [A]>
Return the array’s data as a slice, if it is contiguous and in standard order.
Return None
otherwise.
Trait Implementations
impl<'a, A, D> IntoIterator for ArrayView<'a, A, D> where
D: Dimension,
[src]
D: Dimension,
type Item = &'a A
The type of the elements being iterated over.
type IntoIter = Iter<'a, A, D>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a, A, Slice: ?Sized> From<&'a Slice> for ArrayView<'a, A, Ix1> where
Slice: AsRef<[A]>,
[src]
Slice: AsRef<[A]>,
Implementation of ArrayView::from(&S)
where S
is a slice or slicable.
Create a one-dimensional read-only array view of the data in slice
.
fn from(slice: &'a Slice) -> Self
Performs the conversion.
impl<'a, A, S, D> From<&'a ArrayBase<S, D>> for ArrayView<'a, A, D> where
S: Data<Elem = A>,
D: Dimension,
[src]
S: Data<Elem = A>,
D: Dimension,
Implementation of ArrayView::from(&A)
where A
is an array.
Create a read-only array view of the array.
impl<'a, A, D: Dimension> NdProducer for ArrayView<'a, A, D>
[src]
type Item = &'a A
The element produced per iteration.
type Dim = D
Dimension type
type Ptr = *mut A
type Stride = isize
fn contiguous_stride(&self) -> Self::Stride
fn __private__(&self) -> PrivateMarker
This trait is private to implement; this method exists to make it impossible to implement outside the crate. Read more