pub struct Mask<S = OwnedRepr<bool>, D = Ix2>(/* private fields */)
where
D: Dimension,
S: RawData<Elem = bool>;Implementations§
Source§impl<S, D> Mask<S, D>
impl<S, D> Mask<S, D>
pub fn from_arr(data: ArrayBase<S, D>) -> Self
pub fn apply<A, T, F>( &mut self, data: &ArrayBase<T, D>, fill: A, ) -> ArrayBase<T, D>
pub fn mask_inplace<'a, A, T, F>( &mut self, data: &'a mut ArrayBase<T, D>, fill: A, ) -> &'a mut ArrayBase<T, D>
pub fn as_slice(&self) -> &[bool]where
S: Data,
pub fn as_mut_slice(&mut self) -> &mut [bool]where
S: DataMut,
pub fn dim(&self) -> D::Pattern
pub fn iter(&self) -> Iter<'_, bool, D>where
S: Data,
pub fn iter_mut(&mut self) -> IterMut<'_, bool, D>where
S: DataMut,
pub fn get(&self) -> &ArrayBase<S, D>
pub fn get_mut(&mut self) -> &mut ArrayBase<S, D>
pub fn into_inner(self) -> ArrayBase<S, D>
pub fn ndim(&self) -> usize
pub fn raw_dim(&self) -> D
pub fn set(&mut self, data: ArrayBase<S, D>)
pub fn shape(&self) -> D
Methods from Deref<Target = ArrayBase<S, D>>§
Sourcepub fn len_of(&self, axis: Axis) -> usize
pub fn len_of(&self, axis: Axis) -> usize
Return the length of axis.
The axis should be in the range Axis( 0 .. n ) where n is the
number of dimensions (axes) of the array.
Panics if the axis is out of bounds.
Sourcepub fn dim(&self) -> <D as Dimension>::Pattern
pub fn dim(&self) -> <D as Dimension>::Pattern
Return the shape of the array in its “pattern” form, an integer in the one-dimensional case, tuple in the n-dimensional cases and so on.
Sourcepub fn raw_dim(&self) -> D
pub fn raw_dim(&self) -> D
Return the shape of the array as it’s stored in the array.
This is primarily useful for passing to other ArrayBase
functions, such as when creating another array of the same
shape and dimensionality.
use ndarray::Array;
let a = Array::from_elem((2, 3), 5.);
// Create an array of zeros that's the same shape and dimensionality as `a`.
let b = Array::<f64, _>::zeros(a.raw_dim());Sourcepub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
Return the shape of the array as a slice.
Note that you probably don’t want to use this to create an array of the
same shape as another array because creating an array with e.g.
Array::zeros() using a shape of type &[usize]
results in a dynamic-dimensional array. If you want to create an array
that has the same shape and dimensionality as another array, use
.raw_dim() instead:
use ndarray::{Array, Array2};
let a = Array2::<i32>::zeros((3, 4));
let shape = a.shape();
assert_eq!(shape, &[3, 4]);
// Since `a.shape()` returned `&[usize]`, we get an `ArrayD` instance:
let b = Array::zeros(shape);
assert_eq!(a.clone().into_dyn(), b);
// To get the same dimension type, use `.raw_dim()` instead:
let c = Array::zeros(a.raw_dim());
assert_eq!(a, c);Sourcepub fn stride_of(&self, axis: Axis) -> isize
pub fn stride_of(&self, axis: Axis) -> isize
Return the stride of axis.
The axis should be in the range Axis( 0 .. n ) where n is the
number of dimensions (axes) of the array.
Panics if the axis is out of bounds.
Sourcepub fn view(&self) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
pub fn view(&self) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
Return a read-only view of the array
Sourcepub fn view_mut(&mut self) -> ArrayBase<ViewRepr<&mut A>, D>where
S: DataMut,
pub fn view_mut(&mut self) -> ArrayBase<ViewRepr<&mut A>, D>where
S: DataMut,
Return a read-write view of the array
Sourcepub fn cell_view(&mut self) -> ArrayBase<ViewRepr<&MathCell<A>>, D>where
S: DataMut,
pub fn cell_view(&mut self) -> ArrayBase<ViewRepr<&MathCell<A>>, D>where
S: DataMut,
Return a shared view of the array with elements as if they were embedded in cells.
The cell view requires a mutable borrow of the array. Once borrowed the cell view itself can be copied and accessed without exclusivity.
The view acts “as if” the elements are temporarily in cells, and elements can be changed through shared references using the regular cell methods.
Sourcepub fn to_owned(&self) -> ArrayBase<OwnedRepr<A>, D>
pub fn to_owned(&self) -> ArrayBase<OwnedRepr<A>, D>
Return an uniquely owned copy of the array.
If the input array is contiguous, then the output array will have the same
memory layout. Otherwise, the layout of the output array is unspecified.
If you need a particular layout, you can allocate a new array with the
desired memory layout and .assign() the data.
Alternatively, you can collectan iterator, like this for a result in
standard layout:
Array::from_shape_vec(arr.raw_dim(), arr.iter().cloned().collect()).unwrap()or this for a result in column-major (Fortran) layout:
Array::from_shape_vec(arr.raw_dim().f(), arr.t().iter().cloned().collect()).unwrap()Return a shared ownership (copy on write) array, cloning the array elements if necessary.
Sourcepub fn first(&self) -> Option<&A>where
S: Data,
pub fn first(&self) -> Option<&A>where
S: Data,
Returns a reference to the first element of the array, or None if it
is empty.
§Example
use ndarray::Array3;
let mut a = Array3::<f64>::zeros([3, 4, 2]);
a[[0, 0, 0]] = 42.;
assert_eq!(a.first(), Some(&42.));
let b = Array3::<f64>::zeros([3, 0, 5]);
assert_eq!(b.first(), None);Sourcepub fn first_mut(&mut self) -> Option<&mut A>where
S: DataMut,
pub fn first_mut(&mut self) -> Option<&mut A>where
S: DataMut,
Returns a mutable reference to the first element of the array, or
None if it is empty.
§Example
use ndarray::Array3;
let mut a = Array3::<f64>::zeros([3, 4, 2]);
*a.first_mut().unwrap() = 42.;
assert_eq!(a[[0, 0, 0]], 42.);
let mut b = Array3::<f64>::zeros([3, 0, 5]);
assert_eq!(b.first_mut(), None);Sourcepub fn last(&self) -> Option<&A>where
S: Data,
pub fn last(&self) -> Option<&A>where
S: Data,
Returns a reference to the last element of the array, or None if it
is empty.
§Example
use ndarray::Array3;
let mut a = Array3::<f64>::zeros([3, 4, 2]);
a[[2, 3, 1]] = 42.;
assert_eq!(a.last(), Some(&42.));
let b = Array3::<f64>::zeros([3, 0, 5]);
assert_eq!(b.last(), None);Sourcepub fn last_mut(&mut self) -> Option<&mut A>where
S: DataMut,
pub fn last_mut(&mut self) -> Option<&mut A>where
S: DataMut,
Returns a mutable reference to the last element of the array, or None
if it is empty.
§Example
use ndarray::Array3;
let mut a = Array3::<f64>::zeros([3, 4, 2]);
*a.last_mut().unwrap() = 42.;
assert_eq!(a[[2, 3, 1]], 42.);
let mut b = Array3::<f64>::zeros([3, 0, 5]);
assert_eq!(b.last_mut(), None);Sourcepub fn iter(&self) -> Iter<'_, A, D>where
S: Data,
pub fn iter(&self) -> Iter<'_, A, D>where
S: Data,
Return an iterator of references to the elements of the array.
Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.
Iterator element type is &A.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, A, D>where
S: DataMut,
pub fn iter_mut(&mut self) -> IterMut<'_, A, D>where
S: DataMut,
Return an iterator of mutable references to the elements of the array.
Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.
Iterator element type is &mut A.
Sourcepub fn indexed_iter(&self) -> IndexedIter<'_, A, D>where
S: Data,
pub fn indexed_iter(&self) -> IndexedIter<'_, A, D>where
S: Data,
Return an iterator of indexes and references to the elements of the array.
Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.
Iterator element type is (D::Pattern, &A).
See also Zip::indexed
Sourcepub fn indexed_iter_mut(&mut self) -> IndexedIterMut<'_, A, D>where
S: DataMut,
pub fn indexed_iter_mut(&mut self) -> IndexedIterMut<'_, A, D>where
S: DataMut,
Return an iterator of indexes and mutable references to the elements of the array.
Elements are visited in the logical order of the array, which is where the rightmost index is varying the fastest.
Iterator element type is (D::Pattern, &mut A).
Sourcepub fn slice_mut<I>(
&mut self,
info: I,
) -> ArrayBase<ViewRepr<&mut A>, <I as SliceArg<D>>::OutDim>
pub fn slice_mut<I>( &mut self, info: I, ) -> ArrayBase<ViewRepr<&mut A>, <I as SliceArg<D>>::OutDim>
Sourcepub fn multi_slice_mut<'a, M>(
&'a mut self,
info: M,
) -> <M as MultiSliceArg<'a, A, D>>::Outputwhere
M: MultiSliceArg<'a, A, D>,
S: DataMut,
pub fn multi_slice_mut<'a, M>(
&'a mut self,
info: M,
) -> <M as MultiSliceArg<'a, A, D>>::Outputwhere
M: MultiSliceArg<'a, A, D>,
S: DataMut,
Return multiple disjoint, sliced, mutable views of the array.
See Slicing for full documentation. See also
MultiSliceArg, s!, SliceArg, and
SliceInfo.
Panics if any of the following occur:
- if any of the views would intersect (i.e. if any element would appear in multiple slices)
- if an index is out of bounds or step size is zero
- if
DisIxDynandinfodoes not match the number of array axes
§Example
use ndarray::{arr2, s};
let mut a = arr2(&[[1, 2, 3], [4, 5, 6]]);
let (mut edges, mut middle) = a.multi_slice_mut((s![.., ..;2], s![.., 1]));
edges.fill(1);
middle.fill(0);
assert_eq!(a, arr2(&[[1, 0, 1], [1, 0, 1]]));Sourcepub fn slice_collapse<I>(&mut self, info: I)where
I: SliceArg<D>,
pub fn slice_collapse<I>(&mut self, info: I)where
I: SliceArg<D>,
Slice the array in place without changing the number of dimensions.
In particular, if an axis is sliced with an index, the axis is
collapsed, as in .collapse_axis(), rather than removed, as in
.slice_move() or .index_axis_move().
See Slicing for full documentation.
See also s!, SliceArg, and SliceInfo.
Panics in the following cases:
- if an index is out of bounds
- if a step size is zero
- if
SliceInfoElem::NewAxisis ininfo, e.g. ifNewAxiswas used in thes!macro - if
DisIxDynandinfodoes not match the number of array axes
Sourcepub fn slice_axis(
&self,
axis: Axis,
indices: Slice,
) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
pub fn slice_axis(
&self,
axis: Axis,
indices: Slice,
) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
Return a view of the array, sliced along the specified axis.
Panics if an index is out of bounds or step size is zero.
Panics if axis is out of bounds.
Sourcepub fn slice_axis_mut(
&mut self,
axis: Axis,
indices: Slice,
) -> ArrayBase<ViewRepr<&mut A>, D>where
S: DataMut,
pub fn slice_axis_mut(
&mut self,
axis: Axis,
indices: Slice,
) -> ArrayBase<ViewRepr<&mut A>, D>where
S: DataMut,
Return a mutable view of the array, sliced along the specified axis.
Panics if an index is out of bounds or step size is zero.
Panics if axis is out of bounds.
Sourcepub fn slice_axis_inplace(&mut self, axis: Axis, indices: Slice)
pub fn slice_axis_inplace(&mut self, axis: Axis, indices: Slice)
Slice the array in place along the specified axis.
Panics if an index is out of bounds or step size is zero.
Panics if axis is out of bounds.
Sourcepub fn slice_each_axis<F>(&self, f: F) -> ArrayBase<ViewRepr<&A>, D>
pub fn slice_each_axis<F>(&self, f: F) -> ArrayBase<ViewRepr<&A>, D>
Return a view of a slice of the array, with a closure specifying the slice for each axis.
This is especially useful for code which is generic over the dimensionality of the array.
Panics if an index is out of bounds or step size is zero.
Sourcepub fn slice_each_axis_mut<F>(&mut self, f: F) -> ArrayBase<ViewRepr<&mut A>, D>
pub fn slice_each_axis_mut<F>(&mut self, f: F) -> ArrayBase<ViewRepr<&mut A>, D>
Return a mutable view of a slice of the array, with a closure specifying the slice for each axis.
This is especially useful for code which is generic over the dimensionality of the array.
Panics if an index is out of bounds or step size is zero.
Sourcepub fn slice_each_axis_inplace<F>(&mut self, f: F)
pub fn slice_each_axis_inplace<F>(&mut self, f: F)
Slice the array in place, with a closure specifying the slice for each axis.
This is especially useful for code which is generic over the dimensionality of the array.
Panics if an index is out of bounds or step size is zero.
Sourcepub fn get<I>(&self, index: I) -> Option<&A>
pub fn get<I>(&self, index: I) -> Option<&A>
Return a reference to the element at index, or return None
if the index is out of bounds.
Arrays also support indexing syntax: array[index].
use ndarray::arr2;
let a = arr2(&[[1., 2.],
[3., 4.]]);
assert!(
a.get((0, 1)) == Some(&2.) &&
a.get((0, 2)) == None &&
a[(0, 1)] == 2. &&
a[[0, 1]] == 2.
);Sourcepub fn get_ptr<I>(&self, index: I) -> Option<*const A>where
I: NdIndex<D>,
pub fn get_ptr<I>(&self, index: I) -> Option<*const A>where
I: NdIndex<D>,
Return a raw pointer to the element at index, or return None
if the index is out of bounds.
use ndarray::arr2;
let a = arr2(&[[1., 2.], [3., 4.]]);
let v = a.raw_view();
let p = a.get_ptr((0, 1)).unwrap();
assert_eq!(unsafe { *p }, 2.);Sourcepub fn get_mut<I>(&mut self, index: I) -> Option<&mut A>
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut A>
Return a mutable reference to the element at index, or return None
if the index is out of bounds.
Sourcepub fn get_mut_ptr<I>(&mut self, index: I) -> Option<*mut A>where
S: RawDataMut,
I: NdIndex<D>,
pub fn get_mut_ptr<I>(&mut self, index: I) -> Option<*mut A>where
S: RawDataMut,
I: NdIndex<D>,
Return a raw pointer to the element at index, or return None
if the index is out of bounds.
use ndarray::arr2;
let mut a = arr2(&[[1., 2.], [3., 4.]]);
let v = a.raw_view_mut();
let p = a.get_mut_ptr((0, 1)).unwrap();
unsafe {
*p = 5.;
}
assert_eq!(a.get((0, 1)), Some(&5.));Sourcepub unsafe fn uget<I>(&self, index: I) -> &A
pub unsafe fn uget<I>(&self, index: I) -> &A
Perform unchecked array indexing.
Return a reference to the element at index.
Note: only unchecked for non-debug builds of ndarray.
§Safety
The caller must ensure that the index is in-bounds.
Sourcepub unsafe fn uget_mut<I>(&mut self, index: I) -> &mut A
pub unsafe fn uget_mut<I>(&mut self, index: I) -> &mut A
Perform unchecked array indexing.
Return a mutable reference to the element at index.
Note: Only unchecked for non-debug builds of ndarray.
§Safety
The caller must ensure that:
-
the index is in-bounds and
-
the data is uniquely held by the array. (This property is guaranteed for
ArrayandArrayViewMut, but not forArcArrayorCowArray.)
Sourcepub fn swap<I>(&mut self, index1: I, index2: I)
pub fn swap<I>(&mut self, index1: I, index2: I)
Swap elements at indices index1 and index2.
Indices may be equal.
Panics if an index is out of bounds.
Sourcepub unsafe fn uswap<I>(&mut self, index1: I, index2: I)
pub unsafe fn uswap<I>(&mut self, index1: I, index2: I)
Swap elements unchecked at indices index1 and index2.
Indices may be equal.
Note: only unchecked for non-debug builds of ndarray.
§Safety
The caller must ensure that:
-
both
index1andindex2are in-bounds and -
the data is uniquely held by the array. (This property is guaranteed for
ArrayandArrayViewMut, but not forArcArrayorCowArray.)
Sourcepub fn index_axis(
&self,
axis: Axis,
index: usize,
) -> ArrayBase<ViewRepr<&A>, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
pub fn index_axis(
&self,
axis: Axis,
index: usize,
) -> ArrayBase<ViewRepr<&A>, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
Returns a view restricted to index along the axis, with the axis
removed.
See Subviews for full documentation.
Panics if axis or index is out of bounds.
use ndarray::{arr2, ArrayView, Axis};
let a = arr2(&[[1., 2. ], // ... axis 0, row 0
[3., 4. ], // --- axis 0, row 1
[5., 6. ]]); // ... axis 0, row 2
// . \
// . axis 1, column 1
// axis 1, column 0
assert!(
a.index_axis(Axis(0), 1) == ArrayView::from(&[3., 4.]) &&
a.index_axis(Axis(1), 1) == ArrayView::from(&[2., 4., 6.])
);Sourcepub fn index_axis_mut(
&mut self,
axis: Axis,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
pub fn index_axis_mut(
&mut self,
axis: Axis,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
Returns a mutable view restricted to index along the axis, with the
axis removed.
Panics if axis or index is out of bounds.
use ndarray::{arr2, aview2, Axis};
let mut a = arr2(&[[1., 2. ],
[3., 4. ]]);
// . \
// . axis 1, column 1
// axis 1, column 0
{
let mut column1 = a.index_axis_mut(Axis(1), 1);
column1 += 10.;
}
assert!(
a == aview2(&[[1., 12.],
[3., 14.]])
);Sourcepub fn collapse_axis(&mut self, axis: Axis, index: usize)
pub fn collapse_axis(&mut self, axis: Axis, index: usize)
Selects index along the axis, collapsing the axis into length one.
Panics if axis or index is out of bounds.
Sourcepub fn select(
&self,
axis: Axis,
indices: &[usize],
) -> ArrayBase<OwnedRepr<A>, D>
pub fn select( &self, axis: Axis, indices: &[usize], ) -> ArrayBase<OwnedRepr<A>, D>
Along axis, select arbitrary subviews corresponding to indices
and and copy them into a new array.
Panics if axis or an element of indices is out of bounds.
use ndarray::{arr2, Axis};
let x = arr2(&[[0., 1.],
[2., 3.],
[4., 5.],
[6., 7.],
[8., 9.]]);
let r = x.select(Axis(0), &[0, 4, 3]);
assert!(
r == arr2(&[[0., 1.],
[8., 9.],
[6., 7.]])
);Sourcepub fn rows(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
pub fn rows(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
Return a producer and iterable that traverses over the generalized rows of the array. For a 2D array these are the regular rows.
This is equivalent to .lanes(Axis(n - 1)) where n is self.ndim().
For an array of dimensions a × b × c × … × l × m it has a × b × c × … × l rows each of length m.
For example, in a 2 × 2 × 3 array, each row is 3 elements long and there are 2 × 2 = 4 rows in total.
Iterator element is ArrayView1<A> (1D array view).
use ndarray::arr3;
let a = arr3(&[[[ 0, 1, 2], // -- row 0, 0
[ 3, 4, 5]], // -- row 0, 1
[[ 6, 7, 8], // -- row 1, 0
[ 9, 10, 11]]]); // -- row 1, 1
// `rows` will yield the four generalized rows of the array.
for row in a.rows() {
/* loop body */
}pub fn genrows(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
Sourcepub fn rows_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
pub fn rows_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
Return a producer and iterable that traverses over the generalized rows of the array and yields mutable array views.
Iterator element is ArrayView1<A> (1D read-write array view).
pub fn genrows_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
Sourcepub fn columns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
pub fn columns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
Return a producer and iterable that traverses over the generalized columns of the array. For a 2D array these are the regular columns.
This is equivalent to .lanes(Axis(0)).
For an array of dimensions a × b × c × … × l × m it has b × c × … × l × m columns each of length a.
For example, in a 2 × 2 × 3 array, each column is 2 elements long and there are 2 × 3 = 6 columns in total.
Iterator element is ArrayView1<A> (1D array view).
use ndarray::arr3;
// The generalized columns of a 3D array:
// are directed along the 0th axis: 0 and 6, 1 and 7 and so on...
let a = arr3(&[[[ 0, 1, 2], [ 3, 4, 5]],
[[ 6, 7, 8], [ 9, 10, 11]]]);
// Here `columns` will yield the six generalized columns of the array.
for row in a.columns() {
/* loop body */
}Sourcepub fn gencolumns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
👎Deprecated since 0.15.0: Renamed to .columns()
pub fn gencolumns(&self) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
Return a producer and iterable that traverses over the generalized columns of the array. For a 2D array these are the regular columns.
Renamed to .columns()
Sourcepub fn columns_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
pub fn columns_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
Return a producer and iterable that traverses over the generalized columns of the array and yields mutable array views.
Iterator element is ArrayView1<A> (1D read-write array view).
Sourcepub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
👎Deprecated since 0.15.0: Renamed to .columns_mut()
pub fn gencolumns_mut(&mut self) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
Return a producer and iterable that traverses over the generalized columns of the array and yields mutable array views.
Renamed to .columns_mut()
Sourcepub fn lanes(&self, axis: Axis) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
pub fn lanes(&self, axis: Axis) -> Lanes<'_, A, <D as Dimension>::Smaller>where
S: Data,
Return a producer and iterable that traverses over all 1D lanes
pointing in the direction of axis.
When pointing in the direction of the first axis, they are columns, in the direction of the last axis rows; in general they are all lanes and are one dimensional.
Iterator element is ArrayView1<A> (1D array view).
use ndarray::{arr3, aview1, Axis};
let a = arr3(&[[[ 0, 1, 2],
[ 3, 4, 5]],
[[ 6, 7, 8],
[ 9, 10, 11]]]);
let inner0 = a.lanes(Axis(0));
let inner1 = a.lanes(Axis(1));
let inner2 = a.lanes(Axis(2));
// The first lane for axis 0 is [0, 6]
assert_eq!(inner0.into_iter().next().unwrap(), aview1(&[0, 6]));
// The first lane for axis 1 is [0, 3]
assert_eq!(inner1.into_iter().next().unwrap(), aview1(&[0, 3]));
// The first lane for axis 2 is [0, 1, 2]
assert_eq!(inner2.into_iter().next().unwrap(), aview1(&[0, 1, 2]));Sourcepub fn lanes_mut(
&mut self,
axis: Axis,
) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
pub fn lanes_mut(
&mut self,
axis: Axis,
) -> LanesMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
Return a producer and iterable that traverses over all 1D lanes
pointing in the direction of axis.
Iterator element is ArrayViewMut1<A> (1D read-write array view).
Sourcepub fn outer_iter(&self) -> AxisIter<'_, A, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
pub fn outer_iter(&self) -> AxisIter<'_, A, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
Return an iterator that traverses over the outermost dimension and yields each subview.
This is equivalent to .axis_iter(Axis(0)).
Iterator element is ArrayView<A, D::Smaller> (read-only array view).
Sourcepub fn outer_iter_mut(
&mut self,
) -> AxisIterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
pub fn outer_iter_mut(
&mut self,
) -> AxisIterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
Return an iterator that traverses over the outermost dimension and yields each subview.
This is equivalent to .axis_iter_mut(Axis(0)).
Iterator element is ArrayViewMut<A, D::Smaller> (read-write array view).
Sourcepub fn axis_iter(
&self,
axis: Axis,
) -> AxisIter<'_, A, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
pub fn axis_iter(
&self,
axis: Axis,
) -> AxisIter<'_, A, <D as Dimension>::Smaller>where
S: Data,
D: RemoveAxis,
Return an iterator that traverses over axis
and yields each subview along it.
For example, in a 3 × 4 × 5 array, with axis equal to Axis(2),
the iterator element
is a 3 × 4 subview (and there are 5 in total), as shown
in the picture below.
Iterator element is ArrayView<A, D::Smaller> (read-only array view).
See Subviews for full documentation.
Panics if axis is out of bounds.
Sourcepub fn axis_iter_mut(
&mut self,
axis: Axis,
) -> AxisIterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
pub fn axis_iter_mut(
&mut self,
axis: Axis,
) -> AxisIterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
D: RemoveAxis,
Return an iterator that traverses over axis
and yields each mutable subview along it.
Iterator element is ArrayViewMut<A, D::Smaller>
(read-write array view).
Panics if axis is out of bounds.
Sourcepub fn axis_chunks_iter(
&self,
axis: Axis,
size: usize,
) -> AxisChunksIter<'_, A, D>where
S: Data,
pub fn axis_chunks_iter(
&self,
axis: Axis,
size: usize,
) -> AxisChunksIter<'_, A, D>where
S: Data,
Return an iterator that traverses over axis by chunks of size,
yielding non-overlapping views along that axis.
Iterator element is ArrayView<A, D>
The last view may have less elements if size does not divide
the axis’ dimension.
Panics if axis is out of bounds or if size is zero.
use ndarray::Array;
use ndarray::{arr3, Axis};
let a = Array::from_iter(0..28).into_shape((2, 7, 2)).unwrap();
let mut iter = a.axis_chunks_iter(Axis(1), 2);
// first iteration yields a 2 × 2 × 2 view
assert_eq!(iter.next().unwrap(),
arr3(&[[[ 0, 1], [ 2, 3]],
[[14, 15], [16, 17]]]));
// however the last element is a 2 × 1 × 2 view since 7 % 2 == 1
assert_eq!(iter.next_back().unwrap(), arr3(&[[[12, 13]],
[[26, 27]]]));Sourcepub fn axis_chunks_iter_mut(
&mut self,
axis: Axis,
size: usize,
) -> AxisChunksIterMut<'_, A, D>where
S: DataMut,
pub fn axis_chunks_iter_mut(
&mut self,
axis: Axis,
size: usize,
) -> AxisChunksIterMut<'_, A, D>where
S: DataMut,
Return an iterator that traverses over axis by chunks of size,
yielding non-overlapping read-write views along that axis.
Iterator element is ArrayViewMut<A, D>
Panics if axis is out of bounds or if size is zero.
Sourcepub fn exact_chunks<E>(&self, chunk_size: E) -> ExactChunks<'_, A, D>where
E: IntoDimension<Dim = D>,
S: Data,
pub fn exact_chunks<E>(&self, chunk_size: E) -> ExactChunks<'_, A, D>where
E: IntoDimension<Dim = D>,
S: Data,
Return an exact chunks producer (and iterable).
It produces the whole chunks of a given n-dimensional chunk size, skipping the remainder along each dimension that doesn’t fit evenly.
The produced element is a ArrayView<A, D> with exactly the dimension
chunk_size.
Panics if any dimension of chunk_size is zero
(Panics if D is IxDyn and chunk_size does not match the
number of array axes.)
Sourcepub fn exact_chunks_mut<E>(&mut self, chunk_size: E) -> ExactChunksMut<'_, A, D>where
E: IntoDimension<Dim = D>,
S: DataMut,
pub fn exact_chunks_mut<E>(&mut self, chunk_size: E) -> ExactChunksMut<'_, A, D>where
E: IntoDimension<Dim = D>,
S: DataMut,
Return an exact chunks producer (and iterable).
It produces the whole chunks of a given n-dimensional chunk size, skipping the remainder along each dimension that doesn’t fit evenly.
The produced element is a ArrayViewMut<A, D> with exactly
the dimension chunk_size.
Panics if any dimension of chunk_size is zero
(Panics if D is IxDyn and chunk_size does not match the
number of array axes.)
use ndarray::Array;
use ndarray::arr2;
let mut a = Array::zeros((6, 7));
// Fill each 2 × 2 chunk with the index of where it appeared in iteration
for (i, mut chunk) in a.exact_chunks_mut((2, 2)).into_iter().enumerate() {
chunk.fill(i);
}
// The resulting array is:
assert_eq!(
a,
arr2(&[[0, 0, 1, 1, 2, 2, 0],
[0, 0, 1, 1, 2, 2, 0],
[3, 3, 4, 4, 5, 5, 0],
[3, 3, 4, 4, 5, 5, 0],
[6, 6, 7, 7, 8, 8, 0],
[6, 6, 7, 7, 8, 8, 0]]));Sourcepub fn windows<E>(&self, window_size: E) -> Windows<'_, A, D>where
E: IntoDimension<Dim = D>,
S: Data,
pub fn windows<E>(&self, window_size: E) -> Windows<'_, A, D>where
E: IntoDimension<Dim = D>,
S: Data,
Return a window producer and iterable.
The windows are all distinct overlapping views of size window_size
that fit into the array’s shape.
This produces no elements if the window size is larger than the actual array size along any axis.
The produced element is an ArrayView<A, D> with exactly the dimension
window_size.
Panics if any dimension of window_size is zero.
(Panics if D is IxDyn and window_size does not match the
number of array axes.)
This is an illustration of the 2×2 windows in a 3×4 array:
──▶ Axis(1)
│ ┏━━━━━┳━━━━━┱─────┬─────┐ ┌─────┲━━━━━┳━━━━━┱─────┐ ┌─────┬─────┲━━━━━┳━━━━━┓
▼ ┃ a₀₀ ┃ a₀₁ ┃ │ │ │ ┃ a₀₁ ┃ a₀₂ ┃ │ │ │ ┃ a₀₂ ┃ a₀₃ ┃
Axis(0) ┣━━━━━╋━━━━━╉─────┼─────┤ ├─────╊━━━━━╋━━━━━╉─────┤ ├─────┼─────╊━━━━━╋━━━━━┫
┃ a₁₀ ┃ a₁₁ ┃ │ │ │ ┃ a₁₁ ┃ a₁₂ ┃ │ │ │ ┃ a₁₂ ┃ a₁₃ ┃
┡━━━━━╇━━━━━╃─────┼─────┤ ├─────╄━━━━━╇━━━━━╃─────┤ ├─────┼─────╄━━━━━╇━━━━━┩
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┘ └─────┴─────┴─────┴─────┘ └─────┴─────┴─────┴─────┘
┌─────┬─────┬─────┬─────┐ ┌─────┬─────┬─────┬─────┐ ┌─────┬─────┬─────┬─────┐
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
┢━━━━━╈━━━━━╅─────┼─────┤ ├─────╆━━━━━╈━━━━━╅─────┤ ├─────┼─────╆━━━━━╈━━━━━┪
┃ a₁₀ ┃ a₁₁ ┃ │ │ │ ┃ a₁₁ ┃ a₁₂ ┃ │ │ │ ┃ a₁₂ ┃ a₁₃ ┃
┣━━━━━╋━━━━━╉─────┼─────┤ ├─────╊━━━━━╋━━━━━╉─────┤ ├─────┼─────╊━━━━━╋━━━━━┫
┃ a₂₀ ┃ a₂₁ ┃ │ │ │ ┃ a₂₁ ┃ a₂₂ ┃ │ │ │ ┃ a₂₂ ┃ a₂₃ ┃
┗━━━━━┻━━━━━┹─────┴─────┘ └─────┺━━━━━┻━━━━━┹─────┘ └─────┴─────┺━━━━━┻━━━━━┛Sourcepub fn axis_windows(&self, axis: Axis, window_size: usize) -> Windows<'_, A, D>where
S: Data,
pub fn axis_windows(&self, axis: Axis, window_size: usize) -> Windows<'_, A, D>where
S: Data,
Returns a producer which traverses over all windows of a given length along an axis.
The windows are all distinct, possibly-overlapping views. The shape of each window
is the shape of self, with the length of axis replaced with window_size.
Panics if axis is out-of-bounds or if window_size is zero.
use ndarray::{Array3, Axis, s};
let arr = Array3::from_shape_fn([4, 5, 2], |(i, j, k)| i * 100 + j * 10 + k);
let correct = vec![
arr.slice(s![.., 0..3, ..]),
arr.slice(s![.., 1..4, ..]),
arr.slice(s![.., 2..5, ..]),
];
for (window, correct) in arr.axis_windows(Axis(1), 3).into_iter().zip(&correct) {
assert_eq!(window, correct);
assert_eq!(window.shape(), &[4, 3, 2]);
}Sourcepub fn diag(&self) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
pub fn diag(&self) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
Return a view of the diagonal elements of the array.
The diagonal is simply the sequence indexed by (0, 0, .., 0), (1, 1, …, 1) etc as long as all axes have elements.
Sourcepub fn diag_mut(&mut self) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
pub fn diag_mut(&mut self) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
Return a read-write view over the diagonal elements of the array.
Sourcepub fn is_standard_layout(&self) -> bool
pub fn is_standard_layout(&self) -> bool
Return true if the array data is laid out in contiguous “C order” in
memory (where the last index is the most rapidly varying).
Return false otherwise, i.e. the array is possibly not
contiguous in memory, it has custom strides, etc.
Sourcepub fn as_standard_layout(&self) -> ArrayBase<CowRepr<'_, A>, D>
pub fn as_standard_layout(&self) -> ArrayBase<CowRepr<'_, A>, D>
Return a standard-layout array containing the data, cloning if necessary.
If self is in standard layout, a COW view of the data is returned
without cloning. Otherwise, the data is cloned, and the returned array
owns the cloned data.
use ndarray::Array2;
let standard = Array2::<f64>::zeros((3, 4));
assert!(standard.is_standard_layout());
let cow_view = standard.as_standard_layout();
assert!(cow_view.is_view());
assert!(cow_view.is_standard_layout());
let fortran = standard.reversed_axes();
assert!(!fortran.is_standard_layout());
let cow_owned = fortran.as_standard_layout();
assert!(cow_owned.is_owned());
assert!(cow_owned.is_standard_layout());Sourcepub fn as_ptr(&self) -> *const A
pub fn as_ptr(&self) -> *const A
Return a pointer to the first element in the array.
Raw access to array elements needs to follow the strided indexing scheme: an element at multi-index I in an array with strides S is located at offset
Σ0 ≤ k < d Ik × Sk
where d is self.ndim().
Sourcepub fn as_mut_ptr(&mut self) -> *mut Awhere
S: RawDataMut,
pub fn as_mut_ptr(&mut self) -> *mut Awhere
S: RawDataMut,
Return a mutable pointer to the first element in the array.
This method attempts to unshare the data. If S: DataMut, then the
data is guaranteed to be uniquely held on return.
§Warning
When accessing elements through this pointer, make sure to use strides obtained after calling this method, since the process of unsharing the data may change the strides.
Sourcepub fn raw_view(&self) -> ArrayBase<RawViewRepr<*const A>, D>
pub fn raw_view(&self) -> ArrayBase<RawViewRepr<*const A>, D>
Return a raw view of the array.
Sourcepub fn raw_view_mut(&mut self) -> ArrayBase<RawViewRepr<*mut A>, D>where
S: RawDataMut,
pub fn raw_view_mut(&mut self) -> ArrayBase<RawViewRepr<*mut A>, D>where
S: RawDataMut,
Return a raw mutable view of the array.
This method attempts to unshare the data. If S: DataMut, then the
data is guaranteed to be uniquely held on return.
Sourcepub fn as_slice(&self) -> Option<&[A]>where
S: Data,
pub fn as_slice(&self) -> Option<&[A]>where
S: Data,
Return the array’s data as a slice, if it is contiguous and in standard order.
Return None otherwise.
If this function returns Some(_), then the element order in the slice
corresponds to the logical order of the array’s elements.
Sourcepub fn as_slice_mut(&mut self) -> Option<&mut [A]>where
S: DataMut,
pub fn as_slice_mut(&mut self) -> Option<&mut [A]>where
S: DataMut,
Return the array’s data as a slice, if it is contiguous and in standard order.
Return None otherwise.
Sourcepub fn as_slice_memory_order(&self) -> Option<&[A]>where
S: Data,
pub fn as_slice_memory_order(&self) -> Option<&[A]>where
S: Data,
Return the array’s data as a slice if it is contiguous,
return None otherwise.
If this function returns Some(_), then the elements in the slice
have whatever order the elements have in memory.
Sourcepub fn as_slice_memory_order_mut(&mut self) -> Option<&mut [A]>where
S: DataMut,
pub fn as_slice_memory_order_mut(&mut self) -> Option<&mut [A]>where
S: DataMut,
Return the array’s data as a slice if it is contiguous,
return None otherwise.
In the contiguous case, in order to return a unique reference, this method unshares the data if necessary, but it preserves the existing strides.
Sourcepub fn to_shape<E>(
&self,
new_shape: E,
) -> Result<ArrayBase<CowRepr<'_, A>, <E as ShapeArg>::Dim>, ShapeError>
pub fn to_shape<E>( &self, new_shape: E, ) -> Result<ArrayBase<CowRepr<'_, A>, <E as ShapeArg>::Dim>, ShapeError>
Transform the array into new_shape; any shape with the same number of elements is
accepted.
order specifies the logical order in which the array is to be read and reshaped.
The array is returned as a CowArray; a view if possible, otherwise an owned array.
For example, when starting from the one-dimensional sequence 1 2 3 4 5 6, it would be understood as a 2 x 3 array in row major (“C”) order this way:
1 2 3
4 5 6and as 2 x 3 in column major (“F”) order this way:
1 3 5
2 4 6This example should show that any time we “reflow” the elements in the array to a different
number of rows and columns (or more axes if applicable), it is important to pick an index
ordering, and that’s the reason for the function parameter for order.
Errors if the new shape doesn’t have the same number of elements as the array’s current shape.
use ndarray::array;
use ndarray::Order;
assert!(
array![1., 2., 3., 4., 5., 6.].to_shape(((2, 3), Order::RowMajor)).unwrap()
== array![[1., 2., 3.],
[4., 5., 6.]]
);
assert!(
array![1., 2., 3., 4., 5., 6.].to_shape(((2, 3), Order::ColumnMajor)).unwrap()
== array![[1., 3., 5.],
[2., 4., 6.]]
);Sourcepub fn reshape<E>(&self, shape: E) -> ArrayBase<S, <E as IntoDimension>::Dim>
pub fn reshape<E>(&self, shape: E) -> ArrayBase<S, <E as IntoDimension>::Dim>
Note: Reshape is for ArcArray only. Use .into_shape() for
other arrays and array views.
Transform the array into shape; any shape with the same number of
elements is accepted.
May clone all elements if needed to arrange elements in standard layout (and break sharing).
Panics if shapes are incompatible.
use ndarray::{rcarr1, rcarr2};
assert!(
rcarr1(&[1., 2., 3., 4.]).reshape((2, 2))
== rcarr2(&[[1., 2.],
[3., 4.]])
);Sourcepub fn broadcast<E>(
&self,
dim: E,
) -> Option<ArrayBase<ViewRepr<&A>, <E as IntoDimension>::Dim>>where
E: IntoDimension,
S: Data,
pub fn broadcast<E>(
&self,
dim: E,
) -> Option<ArrayBase<ViewRepr<&A>, <E as IntoDimension>::Dim>>where
E: IntoDimension,
S: Data,
Act like a larger size and/or shape array by broadcasting into a larger shape, if possible.
Return None if shapes can not be broadcast together.
Background
- Two axes are compatible if they are equal, or one of them is 1.
- In this instance, only the axes of the smaller side (self) can be 1.
Compare axes beginning with the last axis of each shape.
For example (1, 2, 4) can be broadcast into (7, 6, 2, 4) because its axes are either equal or 1 (or missing); while (2, 2) can not be broadcast into (2, 4).
The implementation creates a view with strides set to zero for the axes that are to be repeated.
The broadcasting documentation for Numpy has more information.
use ndarray::{aview1, aview2};
assert!(
aview1(&[1., 0.]).broadcast((10, 2)).unwrap()
== aview2(&[[1., 0.]; 10])
);Sourcepub fn swap_axes(&mut self, ax: usize, bx: usize)
pub fn swap_axes(&mut self, ax: usize, bx: usize)
Swap axes ax and bx.
This does not move any data, it just adjusts the array’s dimensions and strides.
Panics if the axes are out of bounds.
use ndarray::arr2;
let mut a = arr2(&[[1., 2., 3.]]);
a.swap_axes(0, 1);
assert!(
a == arr2(&[[1.], [2.], [3.]])
);Sourcepub fn t(&self) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
pub fn t(&self) -> ArrayBase<ViewRepr<&A>, D>where
S: Data,
Return a transposed view of the array.
This is a shorthand for self.view().reversed_axes().
See also the more general methods .reversed_axes() and .swap_axes().
Sourcepub fn max_stride_axis(&self) -> Axis
pub fn max_stride_axis(&self) -> Axis
Return the axis with the greatest stride (by absolute value), preferring axes with len > 1.
Sourcepub fn invert_axis(&mut self, axis: Axis)
pub fn invert_axis(&mut self, axis: Axis)
Reverse the stride of axis.
Panics if the axis is out of bounds.
Sourcepub fn merge_axes(&mut self, take: Axis, into: Axis) -> bool
pub fn merge_axes(&mut self, take: Axis, into: Axis) -> bool
If possible, merge in the axis take to into.
Returns true iff the axes are now merged.
This method merges the axes if movement along the two original axes
(moving fastest along the into axis) can be equivalently represented
as movement along one (merged) axis. Merging the axes preserves this
order in the merged axis. If take and into are the same axis, then
the axis is “merged” if its length is ≤ 1.
If the return value is true, then the following hold:
-
The new length of the
intoaxis is the product of the original lengths of the two axes. -
The new length of the
takeaxis is 0 if the product of the original lengths of the two axes is 0, and 1 otherwise.
If the return value is false, then merging is not possible, and the
original shape and strides have been preserved.
Note that the ordering constraint means that if it’s possible to merge
take into into, it’s usually not possible to merge into into
take, and vice versa.
use ndarray::Array3;
use ndarray::Axis;
let mut a = Array3::<f64>::zeros((2, 3, 4));
assert!(a.merge_axes(Axis(1), Axis(2)));
assert_eq!(a.shape(), &[2, 1, 12]);Panics if an axis is out of bounds.
Sourcepub fn assign<E, S2>(&mut self, rhs: &ArrayBase<S2, E>)
pub fn assign<E, S2>(&mut self, rhs: &ArrayBase<S2, E>)
Perform an elementwise assigment to self from rhs.
If their shapes disagree, rhs is broadcast to the shape of self.
Panics if broadcasting isn’t possible.
Sourcepub fn assign_to<P>(&self, to: P)
pub fn assign_to<P>(&self, to: P)
Perform an elementwise assigment of values cloned from self into array or producer to.
The destination to can be another array or a producer of assignable elements.
AssignElem determines how elements are assigned.
Panics if shapes disagree.
Sourcepub fn zip_mut_with<B, S2, E, F>(&mut self, rhs: &ArrayBase<S2, E>, f: F)
pub fn zip_mut_with<B, S2, E, F>(&mut self, rhs: &ArrayBase<S2, E>, f: F)
Traverse two arrays in unspecified order, in lock step,
calling the closure f on each element pair.
If their shapes disagree, rhs is broadcast to the shape of self.
Panics if broadcasting isn’t possible.
Sourcepub fn fold<'a, F, B>(&'a self, init: B, f: F) -> B
pub fn fold<'a, F, B>(&'a self, init: B, f: F) -> B
Traverse the array elements and apply a fold, returning the resulting value.
Elements are visited in arbitrary order.
Sourcepub fn map<'a, B, F>(&'a self, f: F) -> ArrayBase<OwnedRepr<B>, D>
pub fn map<'a, B, F>(&'a self, f: F) -> ArrayBase<OwnedRepr<B>, D>
Call f by reference on each element and create a new array
with the new values.
Elements are visited in arbitrary order.
Return an array with the same shape as self.
use ndarray::arr2;
let a = arr2(&[[ 0., 1.],
[-1., 2.]]);
assert!(
a.map(|x| *x >= 1.0)
== arr2(&[[false, true],
[false, true]])
);Sourcepub fn map_mut<'a, B, F>(&'a mut self, f: F) -> ArrayBase<OwnedRepr<B>, D>
pub fn map_mut<'a, B, F>(&'a mut self, f: F) -> ArrayBase<OwnedRepr<B>, D>
Call f on a mutable reference of each element and create a new array
with the new values.
Elements are visited in arbitrary order.
Return an array with the same shape as self.
Sourcepub fn mapv<B, F>(&self, f: F) -> ArrayBase<OwnedRepr<B>, D>
pub fn mapv<B, F>(&self, f: F) -> ArrayBase<OwnedRepr<B>, D>
Call f by value on each element and create a new array
with the new values.
Elements are visited in arbitrary order.
Return an array with the same shape as self.
use ndarray::arr2;
let a = arr2(&[[ 0., 1.],
[-1., 2.]]);
assert!(
a.mapv(f32::abs) == arr2(&[[0., 1.],
[1., 2.]])
);Sourcepub fn map_inplace<'a, F>(&'a mut self, f: F)
pub fn map_inplace<'a, F>(&'a mut self, f: F)
Modify the array in place by calling f by mutable reference on each element.
Elements are visited in arbitrary order.
Sourcepub fn mapv_inplace<F>(&mut self, f: F)
pub fn mapv_inplace<F>(&mut self, f: F)
Modify the array in place by calling f by value on each element.
The array is updated with the new values.
Elements are visited in arbitrary order.
use approx::assert_abs_diff_eq;
use ndarray::arr2;
let mut a = arr2(&[[ 0., 1.],
[-1., 2.]]);
a.mapv_inplace(f32::exp);
assert_abs_diff_eq!(
a,
arr2(&[[1.00000, 2.71828],
[0.36788, 7.38906]]),
epsilon = 1e-5,
);Sourcepub fn for_each<'a, F>(&'a self, f: F)
pub fn for_each<'a, F>(&'a self, f: F)
Call f for each element in the array.
Elements are visited in arbitrary order.
Sourcepub fn visit<'a, F>(&'a self, f: F)
👎Deprecated since 0.15.0: Renamed to .for_each()
pub fn visit<'a, F>(&'a self, f: F)
Visit each element in the array by calling f by reference
on each element.
Elements are visited in arbitrary order.
Sourcepub fn fold_axis<B, F>(
&self,
axis: Axis,
init: B,
fold: F,
) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
pub fn fold_axis<B, F>( &self, axis: Axis, init: B, fold: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
Fold along an axis.
Combine the elements of each subview with the previous using the fold
function and initial value init.
Return the result as an Array.
Panics if axis is out of bounds.
Sourcepub fn map_axis<'a, B, F>(
&'a self,
axis: Axis,
mapping: F,
) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
pub fn map_axis<'a, B, F>( &'a self, axis: Axis, mapping: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
Reduce the values along an axis into just one value, producing a new array with one less dimension.
Elements are visited in arbitrary order.
Return the result as an Array.
Panics if axis is out of bounds.
Sourcepub fn map_axis_mut<'a, B, F>(
&'a mut self,
axis: Axis,
mapping: F,
) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
pub fn map_axis_mut<'a, B, F>( &'a mut self, axis: Axis, mapping: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
Reduce the values along an axis into just one value, producing a new array with one less dimension. 1-dimensional lanes are passed as mutable references to the reducer, allowing for side-effects.
Elements are visited in arbitrary order.
Return the result as an Array.
Panics if axis is out of bounds.
Sourcepub fn remove_index(&mut self, axis: Axis, index: usize)
pub fn remove_index(&mut self, axis: Axis, index: usize)
Remove the indexth elements along axis and shift down elements from higher indexes.
Note that this “removes” the elements by swapping them around to the end of the axis and shortening the length of the axis; the elements are not deinitialized or dropped by this, just moved out of view (this only matters for elements with ownership semantics). It’s similar to slicing an owned array in place.
Decreases the length of axis by one.
Panics if axis is out of bounds
Panics if not index < self.len_of(axis).
Sourcepub fn accumulate_axis_inplace<F>(&mut self, axis: Axis, f: F)
pub fn accumulate_axis_inplace<F>(&mut self, axis: Axis, f: F)
Iterates over pairs of consecutive elements along the axis.
The first argument to the closure is an element, and the second argument is the next element along the axis. Iteration is guaranteed to proceed in order along the specified axis, but in all other respects the iteration order is unspecified.
§Example
For example, this can be used to compute the cumulative sum along an axis:
use ndarray::{array, Axis};
let mut arr = array![
[[1, 2], [3, 4], [5, 6]],
[[7, 8], [9, 10], [11, 12]],
];
arr.accumulate_axis_inplace(Axis(1), |&prev, curr| *curr += prev);
assert_eq!(
arr,
array![
[[1, 2], [4, 6], [9, 12]],
[[7, 8], [16, 18], [27, 30]],
],
);Sourcepub fn push_row(
&mut self,
row: ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>,
) -> Result<(), ShapeError>where
A: Clone,
pub fn push_row(
&mut self,
row: ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>,
) -> Result<(), ShapeError>where
A: Clone,
Append a row to an array
The elements from row are cloned and added as a new row in the array.
Errors with a shape error if the length of the row does not match the length of the rows in the array.
The memory layout of the self array matters for ensuring that the append is efficient.
Appending automatically changes memory layout of the array so that it is appended to
along the “growing axis”. However, if the memory layout needs adjusting, the array must
reallocate and move memory.
The operation leaves the existing data in place and is most efficent if one of these is true:
- The axis being appended to is the longest stride axis, i.e the array is in row major (“C”) layout.
- The array has 0 or 1 rows (It is converted to row major)
Ensure appending is efficient by, for example, appending to an empty array and then always pushing/appending along the same axis. For pushing rows, ndarray’s default layout (C order) is efficient.
When repeatedly appending to a single axis, the amortized average complexity of each append is O(m), where m is the length of the row.
use ndarray::{Array, ArrayView, array};
// create an empty array and append
let mut a = Array::zeros((0, 4));
a.push_row(ArrayView::from(&[ 1., 2., 3., 4.])).unwrap();
a.push_row(ArrayView::from(&[-1., -2., -3., -4.])).unwrap();
assert_eq!(
a,
array![[ 1., 2., 3., 4.],
[-1., -2., -3., -4.]]);Sourcepub fn push_column(
&mut self,
column: ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>,
) -> Result<(), ShapeError>where
A: Clone,
pub fn push_column(
&mut self,
column: ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>,
) -> Result<(), ShapeError>where
A: Clone,
Append a column to an array
The elements from column are cloned and added as a new column in the array.
Errors with a shape error if the length of the column does not match the length of the columns in the array.
The memory layout of the self array matters for ensuring that the append is efficient.
Appending automatically changes memory layout of the array so that it is appended to
along the “growing axis”. However, if the memory layout needs adjusting, the array must
reallocate and move memory.
The operation leaves the existing data in place and is most efficent if one of these is true:
- The axis being appended to is the longest stride axis, i.e the array is in column major (“F”) layout.
- The array has 0 or 1 columns (It is converted to column major)
Ensure appending is efficient by, for example, appending to an empty array and then always pushing/appending along the same axis. For pushing columns, column major layout (F order) is efficient.
When repeatedly appending to a single axis, the amortized average complexity of each append is O(m), where m is the length of the column.
use ndarray::{Array, ArrayView, array};
// create an empty array and append
let mut a = Array::zeros((2, 0));
a.push_column(ArrayView::from(&[1., 2.])).unwrap();
a.push_column(ArrayView::from(&[-1., -2.])).unwrap();
assert_eq!(
a,
array![[1., -1.],
[2., -2.]]);Sourcepub fn push(
&mut self,
axis: Axis,
array: ArrayBase<ViewRepr<&A>, <D as Dimension>::Smaller>,
) -> Result<(), ShapeError>where
A: Clone,
D: RemoveAxis,
pub fn push(
&mut self,
axis: Axis,
array: ArrayBase<ViewRepr<&A>, <D as Dimension>::Smaller>,
) -> Result<(), ShapeError>where
A: Clone,
D: RemoveAxis,
Append an array to the array along an axis.
The elements of array are cloned and extend the axis axis in the present array;
self will grow in size by 1 along axis.
Append to the array, where the array being pushed to the array has one dimension less than
the self array. This method is equivalent to append in this way:
self.append(axis, array.insert_axis(axis)).
Errors with a shape error if the shape of self does not match the array-to-append;
all axes except the axis along which it being appended matter for this check:
the shape of self with axis removed must be the same as the shape of array.
The memory layout of the self array matters for ensuring that the append is efficient.
Appending automatically changes memory layout of the array so that it is appended to
along the “growing axis”. However, if the memory layout needs adjusting, the array must
reallocate and move memory.
The operation leaves the existing data in place and is most efficent if axis is a
“growing axis” for the array, i.e. one of these is true:
- The axis is the longest stride axis, for example the 0th axis in a C-layout or the n-1th axis in an F-layout array.
- The axis has length 0 or 1 (It is converted to the new growing axis)
Ensure appending is efficient by for example starting from an empty array and/or always appending to an array along the same axis.
The amortized average complexity of the append, when appending along its growing axis, is O(m) where m is the number of individual elements to append.
The memory layout of the argument array does not matter to the same extent.
use ndarray::{Array, ArrayView, array, Axis};
// create an empty array and push rows to it
let mut a = Array::zeros((0, 4));
let ones = ArrayView::from(&[1.; 4]);
let zeros = ArrayView::from(&[0.; 4]);
a.push(Axis(0), ones).unwrap();
a.push(Axis(0), zeros).unwrap();
a.push(Axis(0), ones).unwrap();
assert_eq!(
a,
array![[1., 1., 1., 1.],
[0., 0., 0., 0.],
[1., 1., 1., 1.]]);Sourcepub fn append(
&mut self,
axis: Axis,
array: ArrayBase<ViewRepr<&A>, D>,
) -> Result<(), ShapeError>where
A: Clone,
D: RemoveAxis,
pub fn append(
&mut self,
axis: Axis,
array: ArrayBase<ViewRepr<&A>, D>,
) -> Result<(), ShapeError>where
A: Clone,
D: RemoveAxis,
Append an array to the array along an axis.
The elements of array are cloned and extend the axis axis in the present array;
self will grow in size by array.len_of(axis) along axis.
Errors with a shape error if the shape of self does not match the array-to-append;
all axes except the axis along which it being appended matter for this check:
the shape of self with axis removed must be the same as the shape of array with
axis removed.
The memory layout of the self array matters for ensuring that the append is efficient.
Appending automatically changes memory layout of the array so that it is appended to
along the “growing axis”. However, if the memory layout needs adjusting, the array must
reallocate and move memory.
The operation leaves the existing data in place and is most efficent if axis is a
“growing axis” for the array, i.e. one of these is true:
- The axis is the longest stride axis, for example the 0th axis in a C-layout or the n-1th axis in an F-layout array.
- The axis has length 0 or 1 (It is converted to the new growing axis)
Ensure appending is efficient by for example starting from an empty array and/or always appending to an array along the same axis.
The amortized average complexity of the append, when appending along its growing axis, is O(m) where m is the number of individual elements to append.
The memory layout of the argument array does not matter to the same extent.
use ndarray::{Array, ArrayView, array, Axis};
// create an empty array and append two rows at a time
let mut a = Array::zeros((0, 4));
let ones = ArrayView::from(&[1.; 8]).into_shape((2, 4)).unwrap();
let zeros = ArrayView::from(&[0.; 8]).into_shape((2, 4)).unwrap();
a.append(Axis(0), ones).unwrap();
a.append(Axis(0), zeros).unwrap();
a.append(Axis(0), ones).unwrap();
assert_eq!(
a,
array![[1., 1., 1., 1.],
[1., 1., 1., 1.],
[0., 0., 0., 0.],
[0., 0., 0., 0.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]]);Sourcepub fn to_vec(&self) -> Vec<A>
pub fn to_vec(&self) -> Vec<A>
Return an vector with the elements of the one-dimensional array.
Sourcepub fn row(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
pub fn row(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
Return an array view of row index.
Panics if index is out of bounds.
use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.row(0), array![1., 2.]);Sourcepub fn row_mut(
&mut self,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
pub fn row_mut(
&mut self,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
Return a mutable array view of row index.
Panics if index is out of bounds.
use ndarray::array;
let mut array = array![[1., 2.], [3., 4.]];
array.row_mut(0)[1] = 5.;
assert_eq!(array, array![[1., 5.], [3., 4.]]);Sourcepub fn nrows(&self) -> usize
pub fn nrows(&self) -> usize
Return the number of rows (length of Axis(0)) in the two-dimensional array.
use ndarray::{array, Axis};
let array = array![[1., 2.],
[3., 4.],
[5., 6.]];
assert_eq!(array.nrows(), 3);
// equivalent ways of getting the dimensions
// get nrows, ncols by using dim:
let (m, n) = array.dim();
assert_eq!(m, array.nrows());
// get length of any particular axis with .len_of()
assert_eq!(m, array.len_of(Axis(0)));Sourcepub fn column(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
pub fn column(&self, index: usize) -> ArrayBase<ViewRepr<&A>, Dim<[usize; 1]>>where
S: Data,
Return an array view of column index.
Panics if index is out of bounds.
use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert_eq!(array.column(0), array![1., 3.]);Sourcepub fn column_mut(
&mut self,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
pub fn column_mut(
&mut self,
index: usize,
) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 1]>>where
S: DataMut,
Return a mutable array view of column index.
Panics if index is out of bounds.
use ndarray::array;
let mut array = array![[1., 2.], [3., 4.]];
array.column_mut(0)[1] = 5.;
assert_eq!(array, array![[1., 2.], [5., 4.]]);Sourcepub fn ncols(&self) -> usize
pub fn ncols(&self) -> usize
Return the number of columns (length of Axis(1)) in the two-dimensional array.
use ndarray::{array, Axis};
let array = array![[1., 2.],
[3., 4.],
[5., 6.]];
assert_eq!(array.ncols(), 2);
// equivalent ways of getting the dimensions
// get nrows, ncols by using dim:
let (m, n) = array.dim();
assert_eq!(n, array.ncols());
// get length of any particular axis with .len_of()
assert_eq!(n, array.len_of(Axis(1)));Sourcepub fn is_square(&self) -> bool
pub fn is_square(&self) -> bool
Return true if the array is square, false otherwise.
§Examples
Square:
use ndarray::array;
let array = array![[1., 2.], [3., 4.]];
assert!(array.is_square());Not square:
use ndarray::array;
let array = array![[1., 2., 5.], [3., 4., 6.]];
assert!(!array.is_square());Sourcepub fn insert_axis_inplace(&mut self, axis: Axis)
pub fn insert_axis_inplace(&mut self, axis: Axis)
Insert new array axis of length 1 at axis, modifying the shape and
strides in-place.
Panics if the axis is out of bounds.
use ndarray::{Axis, arr2, arr3};
let mut a = arr2(&[[1, 2, 3], [4, 5, 6]]).into_dyn();
assert_eq!(a.shape(), &[2, 3]);
a.insert_axis_inplace(Axis(1));
assert_eq!(a, arr3(&[[[1, 2, 3]], [[4, 5, 6]]]).into_dyn());
assert_eq!(a.shape(), &[2, 1, 3]);Sourcepub fn index_axis_inplace(&mut self, axis: Axis, index: usize)
pub fn index_axis_inplace(&mut self, axis: Axis, index: usize)
Collapses the array to index along the axis and removes the axis,
modifying the shape and strides in-place.
Panics if axis or index is out of bounds.
use ndarray::{Axis, arr1, arr2};
let mut a = arr2(&[[1, 2, 3], [4, 5, 6]]).into_dyn();
assert_eq!(a.shape(), &[2, 3]);
a.index_axis_inplace(Axis(1), 1);
assert_eq!(a, arr1(&[2, 5]).into_dyn());
assert_eq!(a.shape(), &[2]);Sourcepub fn sum(&self) -> A
pub fn sum(&self) -> A
Return the sum of all elements in the array.
use ndarray::arr2;
let a = arr2(&[[1., 2.],
[3., 4.]]);
assert_eq!(a.sum(), 10.);Sourcepub fn scalar_sum(&self) -> A
👎Deprecated since 0.15.0: renamed to sum
pub fn scalar_sum(&self) -> A
sumReturn the sum of all elements in the array.
This method has been renamed to .sum()
Sourcepub fn mean(&self) -> Option<A>
pub fn mean(&self) -> Option<A>
Returns the arithmetic mean x̅ of all elements in the array:
1 n
x̅ = ― ∑ xᵢ
n i=1If the array is empty, None is returned.
Panics if A::from_usize() fails to convert the number of elements in the array.
Sourcepub fn product(&self) -> A
pub fn product(&self) -> A
Return the product of all elements in the array.
use ndarray::arr2;
let a = arr2(&[[1., 2.],
[3., 4.]]);
assert_eq!(a.product(), 24.);Sourcepub fn var(&self, ddof: A) -> Awhere
A: Float + FromPrimitive,
pub fn var(&self, ddof: A) -> Awhere
A: Float + FromPrimitive,
Return variance of elements in the array.
The variance is computed using the Welford one-pass algorithm.
The parameter ddof specifies the “delta degrees of freedom”. For
example, to calculate the population variance, use ddof = 0, or to
calculate the sample variance, use ddof = 1.
The variance is defined as:
1 n
variance = ―――――――― ∑ (xᵢ - x̅)²
n - ddof i=1where
1 n
x̅ = ― ∑ xᵢ
n i=1and n is the length of the array.
Panics if ddof is less than zero or greater than n
§Example
use ndarray::array;
use approx::assert_abs_diff_eq;
let a = array![1., -4.32, 1.14, 0.32];
let var = a.var(1.);
assert_abs_diff_eq!(var, 6.7331, epsilon = 1e-4);Sourcepub fn std(&self, ddof: A) -> Awhere
A: Float + FromPrimitive,
pub fn std(&self, ddof: A) -> Awhere
A: Float + FromPrimitive,
Return standard deviation of elements in the array.
The standard deviation is computed from the variance using the Welford one-pass algorithm.
The parameter ddof specifies the “delta degrees of freedom”. For
example, to calculate the population standard deviation, use ddof = 0,
or to calculate the sample standard deviation, use ddof = 1.
The standard deviation is defined as:
⎛ 1 n ⎞
stddev = sqrt ⎜ ―――――――― ∑ (xᵢ - x̅)²⎟
⎝ n - ddof i=1 ⎠where
1 n
x̅ = ― ∑ xᵢ
n i=1and n is the length of the array.
Panics if ddof is less than zero or greater than n
§Example
use ndarray::array;
use approx::assert_abs_diff_eq;
let a = array![1., -4.32, 1.14, 0.32];
let stddev = a.std(1.);
assert_abs_diff_eq!(stddev, 2.59483, epsilon = 1e-4);Sourcepub fn sum_axis(
&self,
axis: Axis,
) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
pub fn sum_axis( &self, axis: Axis, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
Return sum along axis.
use ndarray::{aview0, aview1, arr2, Axis};
let a = arr2(&[[1., 2., 3.],
[4., 5., 6.]]);
assert!(
a.sum_axis(Axis(0)) == aview1(&[5., 7., 9.]) &&
a.sum_axis(Axis(1)) == aview1(&[6., 15.]) &&
a.sum_axis(Axis(0)).sum_axis(Axis(0)) == aview0(&21.)
);Panics if axis is out of bounds.
Sourcepub fn mean_axis(
&self,
axis: Axis,
) -> Option<ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>>
pub fn mean_axis( &self, axis: Axis, ) -> Option<ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>>
Return mean along axis.
Return None if the length of the axis is zero.
Panics if axis is out of bounds or if A::from_usize()
fails for the axis length.
use ndarray::{aview0, aview1, arr2, Axis};
let a = arr2(&[[1., 2., 3.],
[4., 5., 6.]]);
assert!(
a.mean_axis(Axis(0)).unwrap() == aview1(&[2.5, 3.5, 4.5]) &&
a.mean_axis(Axis(1)).unwrap() == aview1(&[2., 5.]) &&
a.mean_axis(Axis(0)).unwrap().mean_axis(Axis(0)).unwrap() == aview0(&3.5)
);Sourcepub fn var_axis(
&self,
axis: Axis,
ddof: A,
) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
pub fn var_axis( &self, axis: Axis, ddof: A, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
Return variance along axis.
The variance is computed using the Welford one-pass algorithm.
The parameter ddof specifies the “delta degrees of freedom”. For
example, to calculate the population variance, use ddof = 0, or to
calculate the sample variance, use ddof = 1.
The variance is defined as:
1 n
variance = ―――――――― ∑ (xᵢ - x̅)²
n - ddof i=1where
1 n
x̅ = ― ∑ xᵢ
n i=1and n is the length of the axis.
Panics if ddof is less than zero or greater than n, if axis
is out of bounds, or if A::from_usize() fails for any any of the
numbers in the range 0..=n.
§Example
use ndarray::{aview1, arr2, Axis};
let a = arr2(&[[1., 2.],
[3., 4.],
[5., 6.]]);
let var = a.var_axis(Axis(0), 1.);
assert_eq!(var, aview1(&[4., 4.]));Sourcepub fn std_axis(
&self,
axis: Axis,
ddof: A,
) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
pub fn std_axis( &self, axis: Axis, ddof: A, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
Return standard deviation along axis.
The standard deviation is computed from the variance using the Welford one-pass algorithm.
The parameter ddof specifies the “delta degrees of freedom”. For
example, to calculate the population standard deviation, use ddof = 0,
or to calculate the sample standard deviation, use ddof = 1.
The standard deviation is defined as:
⎛ 1 n ⎞
stddev = sqrt ⎜ ―――――――― ∑ (xᵢ - x̅)²⎟
⎝ n - ddof i=1 ⎠where
1 n
x̅ = ― ∑ xᵢ
n i=1and n is the length of the axis.
Panics if ddof is less than zero or greater than n, if axis
is out of bounds, or if A::from_usize() fails for any any of the
numbers in the range 0..=n.
§Example
use ndarray::{aview1, arr2, Axis};
let a = arr2(&[[1., 2.],
[3., 4.],
[5., 6.]]);
let stddev = a.std_axis(Axis(0), 1.);
assert_eq!(stddev, aview1(&[2., 2.]));Sourcepub fn dot<Rhs>(
&self,
rhs: &Rhs,
) -> <ArrayBase<S, Dim<[usize; 1]>> as Dot<Rhs>>::Output
pub fn dot<Rhs>( &self, rhs: &Rhs, ) -> <ArrayBase<S, Dim<[usize; 1]>> as Dot<Rhs>>::Output
Perform dot product or matrix multiplication of arrays self and rhs.
Rhs may be either a one-dimensional or a two-dimensional array.
If Rhs is one-dimensional, then the operation is a vector dot
product, which is the sum of the elementwise products (no conjugation
of complex operands, and thus not their inner product). In this case,
self and rhs must be the same length.
If Rhs is two-dimensional, then the operation is matrix
multiplication, where self is treated as a row vector. In this case,
if self is shape M, then rhs is shape M × N and the result is
shape N.
Panics if the array shapes are incompatible.
Note: If enabled, uses blas dot for elements of f32, f64 when memory
layout allows.
Sourcepub fn dot<Rhs>(
&self,
rhs: &Rhs,
) -> <ArrayBase<S, Dim<[usize; 2]>> as Dot<Rhs>>::Output
pub fn dot<Rhs>( &self, rhs: &Rhs, ) -> <ArrayBase<S, Dim<[usize; 2]>> as Dot<Rhs>>::Output
Perform matrix multiplication of rectangular arrays self and rhs.
Rhs may be either a one-dimensional or a two-dimensional array.
If Rhs is two-dimensional, they array shapes must agree in the way that
if self is M × N, then rhs is N × K.
Return a result array with shape M × K.
Panics if shapes are incompatible or the number of elements in the
result would overflow isize.
Note: If enabled, uses blas gemv/gemm for elements of f32, f64
when memory layout allows. The default matrixmultiply backend
is otherwise used for f32, f64 for all memory layouts.
use ndarray::arr2;
let a = arr2(&[[1., 2.],
[0., 1.]]);
let b = arr2(&[[1., 2.],
[2., 3.]]);
assert!(
a.dot(&b) == arr2(&[[5., 8.],
[2., 3.]])
);Sourcepub fn scaled_add<S2, E>(&mut self, alpha: A, rhs: &ArrayBase<S2, E>)
pub fn scaled_add<S2, E>(&mut self, alpha: A, rhs: &ArrayBase<S2, E>)
Perform the operation self += alpha * rhs efficiently, where
alpha is a scalar and rhs is another array. This operation is
also known as axpy in BLAS.
If their shapes disagree, rhs is broadcast to the shape of self.
Panics if broadcasting isn’t possible.
Sourcepub fn to_slice(&self) -> Option<&'a [A]>
pub fn to_slice(&self) -> Option<&'a [A]>
Return the array’s data as a slice, if it is contiguous and in standard order.
Return None otherwise.
Note that while the method is similar to ArrayBase::as_slice(), this method transfers
the view’s lifetime to the slice, so it is a bit more powerful.
Sourcepub fn to_slice_memory_order(&self) -> Option<&'a [A]>
pub fn to_slice_memory_order(&self) -> Option<&'a [A]>
Return the array’s data as a slice, if it is contiguous.
Return None otherwise.
Note that while the method is similar to
ArrayBase::as_slice_memory_order(), this method transfers the view’s
lifetime to the slice, so it is a bit more powerful.