pub struct Array<T> { /* private fields */ }
Expand description
An N-dimensional strided array.
Implementations§
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable reference to the underlying data as a flat slice in row-major order.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Returns the number of dimensions of the array.
Sourcepub fn from_element<S>(element: T, shape: S) -> Self
pub fn from_element<S>(element: T, shape: S) -> Self
Creates a new array by repeating a single element to a shape.
Sourcepub fn from_iter<I, S>(iter: I, shape: S) -> Result<Self, ShapeError>
pub fn from_iter<I, S>(iter: I, shape: S) -> Result<Self, ShapeError>
Creates a new array from an iterator an its shape.
§Errors
If the number of items in the iterator does not match the provided shape.
Sourcepub fn get<I>(&self, index: I) -> Option<&T>
pub fn get<I>(&self, index: I) -> Option<&T>
Returns the element at the provided index if in bounds, and None
otherwise,
Sourcepub fn get_axis(&self, axis: Axis, index: usize) -> Option<View<'_, T>>
pub fn get_axis(&self, axis: Axis, index: usize) -> Option<View<'_, T>>
Returns a view of the array along the provided axis at the provided index if in bounds, and
None
otherwise.
See Array::index_axis
for a panicking version.
Sourcepub fn get_mut<I>(&mut self, index: I) -> Option<&mut T>
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut T>
Returns a mutable reference to the element at the provided index if in bounds, and None
otherwise,
Sourcepub fn index_axis(&self, axis: Axis, index: usize) -> View<'_, T>
pub fn index_axis(&self, axis: Axis, index: usize) -> View<'_, T>
Returns a view of the array along the provided axis at the provided index if in bounds.
§Panics
If the axis or the index is not in bounds, see Array::get_axis
for a fallible version.
Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over the underlying data in row-major order.
Sourcepub fn iter_axis(&self, axis: Axis) -> AxisIter<'_, T> ⓘ
pub fn iter_axis(&self, axis: Axis) -> AxisIter<'_, T> ⓘ
Returns an iterator over views of the array along the provided axis.
Sourcepub fn iter_indices(&self) -> IndicesIter<'_> ⓘ
pub fn iter_indices(&self) -> IndicesIter<'_> ⓘ
Returns an iterator over indices of the array in row-major order.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns an iterator over mutable references to the underlying data in row-major order.
Sourcepub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
pub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
Creates a new array from data in row-major order and a shape.
§Errors
If the number of items in the data does not match the provided shape.
Sourcepub fn new_unchecked<D, S>(data: D, shape: S) -> Self
pub fn new_unchecked<D, S>(data: D, shape: S) -> Self
Creates a new array from data in row-major order and a shape.
Prefer using Array::new
to ensure the data fits the provided shape.
It is a logic error where this is not true, though it can not trigger unsafe behaviour.