Type Alias rerun::external::ndarray::ArrayViewD

source ·
pub type ArrayViewD<'a, A> = ArrayBase<ViewRepr<&'a A>, Dim<IxDynImpl>>;
Expand description

dynamic-dimensional array view

Aliased Type§

struct ArrayViewD<'a, A> { /* private fields */ }

Implementations

source§

impl<S, A, D> ArrayBase<S, D>
where S: DataOwned<Elem = A>, D: Dimension,

§Constructor methods for n-dimensional arrays.

The shape argument can be an integer or a tuple of integers to specify a static size. For example 10 makes a length 10 one-dimensional array (dimension type Ix1) and (5, 6) a 5 × 6 array (dimension type Ix2).

With the trait ShapeBuilder in scope, there is the method .f() to select column major (“f” order) memory layout instead of the default row major. For example Array::zeros((5, 6).f()) makes a column major 5 × 6 array.

Use IxDyn for the shape to create an array with dynamic number of axes.

Finally, the few constructors that take a completely general Into<StrideShape> argument optionally support custom strides, for example a shape given like (10, 2, 2).strides((1, 10, 20)) is valid.

source

pub fn from_elem<Sh>(shape: Sh, elem: A) -> ArrayBase<S, D>
where A: Clone, Sh: ShapeBuilder<Dim = D>,

Create an array with copies of elem, shape shape.

Panics if the product of non-zero axis lengths overflows isize.

use ndarray::{Array, arr3, ShapeBuilder};

let a = Array::from_elem((2, 2, 2), 1.);

assert!(
    a == arr3(&[[[1., 1.],
                 [1., 1.]],
                [[1., 1.],
                 [1., 1.]]])
);
assert!(a.strides() == &[4, 2, 1]);

let b = Array::from_elem((2, 2, 2).f(), 1.);
assert!(b.strides() == &[1, 2, 4]);
source

pub fn zeros<Sh>(shape: Sh) -> ArrayBase<S, D>
where A: Clone + Zero, Sh: ShapeBuilder<Dim = D>,

Create an array with zeros, shape shape.

Panics if the product of non-zero axis lengths overflows isize.

source

pub fn ones<Sh>(shape: Sh) -> ArrayBase<S, D>
where A: Clone + One, Sh: ShapeBuilder<Dim = D>,

Create an array with ones, shape shape.

Panics if the product of non-zero axis lengths overflows isize.

source

pub fn default<Sh>(shape: Sh) -> ArrayBase<S, D>
where A: Default, Sh: ShapeBuilder<Dim = D>,

Create an array with default values, shape shape

Panics if the product of non-zero axis lengths overflows isize.

source

pub fn from_shape_simple_fn<Sh, F>(shape: Sh, f: F) -> ArrayBase<S, D>
where Sh: ShapeBuilder<Dim = D>, F: FnMut() -> A,

Create an array with values created by the function f.

f is called with no argument, and it should return the element to create. If the precise index of the element to create is needed, use from_shape_fn instead.

This constructor can be useful if the element order is not important, for example if they are identical or random.

Panics if the product of non-zero axis lengths overflows isize.

source

pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> ArrayBase<S, D>
where Sh: ShapeBuilder<Dim = D>, F: FnMut(<D as Dimension>::Pattern) -> A,

Create an array with values created by the function f.

f is called with the index of the element to create; the elements are visited in arbitrary order.

Panics if the product of non-zero axis lengths overflows isize.

use ndarray::{Array, arr2};

// Create a table of i × j (with i and j from 1 to 3)
let ij_table = Array::from_shape_fn((3, 3), |(i, j)| (1 + i) * (1 + j));

assert_eq!(
    ij_table,
    arr2(&[[1, 2, 3],
           [2, 4, 6],
           [3, 6, 9]])
);
source

pub fn from_shape_vec<Sh>( shape: Sh, v: Vec<A>, ) -> Result<ArrayBase<S, D>, ShapeError>
where Sh: Into<StrideShape<D>>,

Create an array with the given shape from a vector. (No cloning of elements needed.)


For a contiguous c- or f-order shape, the following applies:

Errors if shape does not correspond to the number of elements in v or if the shape/strides would result in overflowing isize.


For custom strides, the following applies:

Errors if strides and dimensions can point out of bounds of v, if strides allow multiple indices to point to the same element, or if the shape/strides would result in overflowing isize.

use ndarray::Array;
use ndarray::ShapeBuilder; // Needed for .strides() method
use ndarray::arr2;

let a = Array::from_shape_vec((2, 2), vec![1., 2., 3., 4.]);
assert!(a.is_ok());

let b = Array::from_shape_vec((2, 2).strides((1, 2)),
                              vec![1., 2., 3., 4.]).unwrap();
assert!(
    b == arr2(&[[1., 3.],
                [2., 4.]])
);
source

pub unsafe fn from_shape_vec_unchecked<Sh>( shape: Sh, v: Vec<A>, ) -> ArrayBase<S, D>
where Sh: Into<StrideShape<D>>,

Creates an array from a vector and interpret it according to the provided shape and strides. (No cloning of elements needed.)

§Safety

The caller must ensure that the following conditions are met:

  1. The ndim of dim and strides must be the same.

  2. The product of non-zero axis lengths must not exceed isize::MAX.

  3. For axes with length > 1, the pointer cannot move outside the slice.

  4. If the array will be empty (any axes are zero-length), the difference between the least address and greatest address accessible by moving along all axes must be ≤ v.len().

    If the array will not be empty, the difference between the least address and greatest address accessible by moving along all axes must be < v.len().

  5. The strides must not allow any element to be referenced by two different indices.

source

pub fn uninit<Sh>(shape: Sh) -> ArrayBase<<S as DataOwned>::MaybeUninit, D>
where Sh: ShapeBuilder<Dim = D>,

Create an array with uninitialized elements, shape shape.

The uninitialized elements of type A are represented by the type MaybeUninit<A>, an easier way to handle uninit values correctly.

Only when the array is completely initialized with valid elements, can it be converted to an array of A elements using .assume_init().

Panics if the number of elements in shape would overflow isize.

§Safety

The whole of the array must be initialized before it is converted using .assume_init() or otherwise traversed/read with the element type A.

§Examples

It is possible to assign individual values through *elt = MaybeUninit::new(value) and so on.

use ndarray::{s, Array2};

// Example Task: Let's create a column shifted copy of the input

fn shift_by_two(a: &Array2<f32>) -> Array2<f32> {
    // create an uninitialized array
    let mut b = Array2::uninit(a.dim());

    // two first columns in b are two last in a
    // rest of columns in b are the initial columns in a

    a.slice(s![.., -2..]).assign_to(b.slice_mut(s![.., ..2]));
    a.slice(s![.., 2..]).assign_to(b.slice_mut(s![.., ..-2]));

    // Now we can promise that `b` is safe to use with all operations
    unsafe {
        b.assume_init()
    }
}
source

pub fn build_uninit<Sh, F>( shape: Sh, builder: F, ) -> ArrayBase<<S as DataOwned>::MaybeUninit, D>
where Sh: ShapeBuilder<Dim = D>, F: FnOnce(ArrayBase<ViewRepr<&mut MaybeUninit<A>>, D>),

Create an array with uninitialized elements, shape shape.

The uninitialized elements of type A are represented by the type MaybeUninit<A>, an easier way to handle uninit values correctly.

The builder closure gets unshared access to the array through a view and can use it to modify the array before it is returned. This allows initializing the array for any owned array type (avoiding clone requirements for copy-on-write, because the array is unshared when initially created).

Only when the array is completely initialized with valid elements, can it be converted to an array of A elements using .assume_init().

Panics if the number of elements in shape would overflow isize.

§Safety

The whole of the array must be initialized before it is converted using .assume_init() or otherwise traversed/read with the element type A.

source§

impl<A, S, D> ArrayBase<S, D>
where S: RawData<Elem = A>, D: Dimension,

§Methods For All Array Types

source

pub fn len(&self) -> usize

Return the total number of elements in the array.

source

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.

source

pub fn is_empty(&self) -> bool

Return whether the array has any elements

source

pub fn ndim(&self) -> usize

Return the number of dimensions (axes) in the array

source

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.

source

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());
source

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);
source

pub fn strides(&self) -> &[isize]

Return the strides of the array as a slice.

source

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.

source

pub fn view(&self) -> ArrayBase<ViewRepr<&A>, D>
where S: Data,

Return a read-only view of the array

source

pub fn view_mut(&mut self) -> ArrayBase<ViewRepr<&mut A>, D>
where S: DataMut,

Return a read-write view of the array

source

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.

source

pub fn to_owned(&self) -> ArrayBase<OwnedRepr<A>, D>
where A: Clone, S: Data,

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()
source

pub fn to_shared(&self) -> ArrayBase<OwnedArcRepr<A>, D>
where A: Clone, S: Data,

Return a shared ownership (copy on write) array, cloning the array elements if necessary.

source

pub fn into_owned(self) -> ArrayBase<OwnedRepr<A>, D>
where A: Clone, S: Data,

Turn the array into a uniquely owned array, cloning the array elements if necessary.

source

pub fn try_into_owned_nocopy( self, ) -> Result<ArrayBase<OwnedRepr<A>, D>, ArrayBase<S, D>>
where S: Data,

Converts the array into Array<A, D> if this is possible without cloning the array elements. Otherwise, returns self unchanged.

use ndarray::{array, rcarr2, ArcArray2, Array2};

// Reference-counted, clone-on-write `ArcArray`.
let a: ArcArray2<_> = rcarr2(&[[1., 2.], [3., 4.]]);
{
    // Another reference to the same data.
    let b: ArcArray2<_> = a.clone();
    // Since there are two references to the same data, `.into_owned()`
    // would require cloning the data, so `.try_into_owned_nocopy()`
    // returns `Err`.
    assert!(b.try_into_owned_nocopy().is_err());
}
// Here, since the second reference has been dropped, the `ArcArray`
// can be converted into an `Array` without cloning the data.
let unique: Array2<_> = a.try_into_owned_nocopy().unwrap();
assert_eq!(unique, array![[1., 2.], [3., 4.]]);
source

pub fn into_shared(self) -> ArrayBase<OwnedArcRepr<A>, D>
where A: Clone, S: DataOwned,

Turn the array into a shared ownership (copy on write) array, cloning the array elements if necessary.

If you want to generalize over Array and ArcArray inputs but avoid an A: Clone bound, use Into::<ArcArray<A, D>>::into instead of this method.

source

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);
source

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);
source

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);
source

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);
source

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.

source

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.

source

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

source

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).

source

pub fn slice<I>( &self, info: I, ) -> ArrayBase<ViewRepr<&A>, <I as SliceArg<D>>::OutDim>
where I: SliceArg<D>, S: Data,

Return a sliced view of the array.

See Slicing for full documentation. See also s!, SliceArg, and SliceInfo.

Panics if an index is out of bounds or step size is zero.
(Panics if D is IxDyn and info does not match the number of array axes.)

source

pub fn slice_mut<I>( &mut self, info: I, ) -> ArrayBase<ViewRepr<&mut A>, <I as SliceArg<D>>::OutDim>
where I: SliceArg<D>, S: DataMut,

Return a sliced read-write view of the array.

See Slicing for full documentation. See also s!, SliceArg, and SliceInfo.

Panics if an index is out of bounds or step size is zero.
(Panics if D is IxDyn and info does not match the number of array axes.)

source

pub fn multi_slice_mut<'a, M>( &'a mut self, info: M, ) -> <M as MultiSliceArg<'a, A, D>>::Output
where 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 D is IxDyn and info does 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]]));
source

pub fn slice_move<I>(self, info: I) -> ArrayBase<S, <I as SliceArg<D>>::OutDim>
where I: SliceArg<D>,

Slice the array, possibly changing the number of dimensions.

See Slicing for full documentation. See also s!, SliceArg, and SliceInfo.

Panics if an index is out of bounds or step size is zero.
(Panics if D is IxDyn and info does not match the number of array axes.)

source

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::NewAxis is in info, e.g. if NewAxis was used in the s! macro
  • if D is IxDyn and info does not match the number of array axes
source

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.

source

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.

source

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.

source

pub fn slice_axis_move(self, axis: Axis, indices: Slice) -> ArrayBase<S, D>

Slice the array in place along the specified axis, then return the sliced array.

Panics if an index is out of bounds or step size is zero.
Panics if axis is out of bounds.

source

pub fn slice_each_axis<F>(&self, f: F) -> ArrayBase<ViewRepr<&A>, D>
where F: FnMut(AxisDescription) -> Slice, S: Data,

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.

source

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.

source

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.

source

pub fn get<I>(&self, index: I) -> Option<&A>
where S: Data, I: NdIndex<D>,

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.
);
source

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.);
source

pub fn get_mut<I>(&mut self, index: I) -> Option<&mut A>
where S: DataMut, I: NdIndex<D>,

Return a mutable reference to the element at index, or return None if the index is out of bounds.

source

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.));
source

pub unsafe fn uget<I>(&self, index: I) -> &A
where S: Data, I: NdIndex<D>,

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.

source

pub unsafe fn uget_mut<I>(&mut self, index: I) -> &mut A
where S: DataMut, I: NdIndex<D>,

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:

  1. the index is in-bounds and

  2. the data is uniquely held by the array. (This property is guaranteed for Array and ArrayViewMut, but not for ArcArray or CowArray.)

source

pub fn swap<I>(&mut self, index1: I, index2: I)
where S: DataMut, I: NdIndex<D>,

Swap elements at indices index1 and index2.

Indices may be equal.

Panics if an index is out of bounds.

source

pub unsafe fn uswap<I>(&mut self, index1: I, index2: I)
where S: DataMut, I: NdIndex<D>,

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:

  1. both index1 and index2 are in-bounds and

  2. the data is uniquely held by the array. (This property is guaranteed for Array and ArrayViewMut, but not for ArcArray or CowArray.)

source

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.])
);
source

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.]])
);
source

pub fn index_axis_move( self, axis: Axis, index: usize, ) -> ArrayBase<S, <D as Dimension>::Smaller>
where D: RemoveAxis,

Collapses the array to index along the axis and removes the axis.

See .index_axis() and Subviews for full documentation.

Panics if axis or index is out of bounds.

source

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.

source

pub fn select( &self, axis: Axis, indices: &[usize], ) -> ArrayBase<OwnedRepr<A>, D>
where A: Clone, S: Data, D: RemoveAxis,

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.]])
);
source

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 */
}
source

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).

source

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 column in a.columns() {
    /* loop body */
}
source

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).

source

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]));
source

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).

source

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).

source

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).

source

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.

source

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.

source

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_with_order((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]]]));
source

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.

source

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.)

source

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]]));
source

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 is essentially equivalent to [.windows_with_stride()] with unit stride.

source

pub fn windows_with_stride<E>( &self, window_size: E, stride: E, ) -> Windows<'_, A, D>
where E: IntoDimension<Dim = D>, S: Data,

Return a window producer and iterable.

The windows are all distinct views of size window_size that fit into the array’s shape.

The stride is ordered by the outermost axis.
Hence, a (x₀, x₁, …, xₙ) stride will be applied to (A₀, A₁, …, Aₙ) where Aₓ stands for Axis(x).

This produces all windows that fit within the array for the given stride, assuming the window size is not larger than the array size.

The produced element is an ArrayView<A, D> with exactly the dimension window_size.

Note that passing a stride of only ones is similar to calling ArrayBase::windows().

Panics if any dimension of window_size or stride is zero.
(Panics if D is IxDyn and window_size or stride does not match the number of array axes.)

This is the same illustration found in ArrayBase::windows(), 2×2 windows in a 3×4 array, but now with a (1, 2) stride:

         ──▶ Axis(1)

     │   ┏━━━━━┳━━━━━┱─────┬─────┐   ┌─────┬─────┲━━━━━┳━━━━━┓
     ▼   ┃ a₀₀ ┃ a₀₁ ┃     │     │   │     │     ┃ a₀₂ ┃ a₀₃ ┃
Axis(0)  ┣━━━━━╋━━━━━╉─────┼─────┤   ├─────┼─────╊━━━━━╋━━━━━┫
         ┃ a₁₀ ┃ a₁₁ ┃     │     │   │     │     ┃ a₁₂ ┃ a₁₃ ┃
         ┡━━━━━╇━━━━━╃─────┼─────┤   ├─────┼─────╄━━━━━╇━━━━━┩
         │     │     │     │     │   │     │     │     │     │
         └─────┴─────┴─────┴─────┘   └─────┴─────┴─────┴─────┘

         ┌─────┬─────┬─────┬─────┐   ┌─────┬─────┬─────┬─────┐
         │     │     │     │     │   │     │     │     │     │
         ┢━━━━━╈━━━━━╅─────┼─────┤   ├─────┼─────╆━━━━━╈━━━━━┪
         ┃ a₁₀ ┃ a₁₁ ┃     │     │   │     │     ┃ a₁₂ ┃ a₁₃ ┃
         ┣━━━━━╋━━━━━╉─────┼─────┤   ├─────┼─────╊━━━━━╋━━━━━┫
         ┃ a₂₀ ┃ a₂₁ ┃     │     │   │     │     ┃ a₂₂ ┃ a₂₃ ┃
         ┗━━━━━┻━━━━━┹─────┴─────┘   └─────┴─────┺━━━━━┻━━━━━┛
source

pub fn axis_windows( &self, axis: Axis, window_size: usize, ) -> AxisWindows<'_, 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]);
}
source

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.

source

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.

source

pub fn into_diag(self) -> ArrayBase<S, Dim<[usize; 1]>>

Return the diagonal as a one-dimensional array.

source

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.

source

pub fn as_standard_layout(&self) -> ArrayBase<CowRepr<'_, A>, D>
where S: Data<Elem = A>, A: Clone,

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());
source

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().

source

pub fn as_mut_ptr(&mut self) -> *mut A
where 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.

source

pub fn raw_view(&self) -> ArrayBase<RawViewRepr<*const A>, D>

Return a raw view of the array.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn to_shape<E>( &self, new_shape: E, ) -> Result<ArrayBase<CowRepr<'_, A>, <E as ShapeArg>::Dim>, ShapeError>
where E: ShapeArg, A: Clone, S: Data,

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 6

and as 2 x 3 in column major (“F”) order this way:

1 3 5
2 4 6

This 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.

The new_shape parameter should be a dimension and an optional order like these examples:

(3, 4)                          // Shape 3 x 4 with default order (RowMajor)
((3, 4), Order::RowMajor))      // use specific order
((3, 4), Order::ColumnMajor))   // use specific order
((3, 4), Order::C))             // use shorthand for order - shorthands C and F

Errors if the new shape doesn’t have the same number of elements as the array’s current shape.

§Example
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.]]
);
source

pub fn into_shape_with_order<E>( self, shape: E, ) -> Result<ArrayBase<S, <E as ShapeArg>::Dim>, ShapeError>
where E: ShapeArg,

Transform the array into shape; any shape with the same number of elements is accepted, but the source array must be contiguous.

If an index ordering is not specified, the default is RowMajor. The operation will only succeed if the array’s memory layout is compatible with the index ordering, so that the array elements can be rearranged in place.

If required use .to_shape() or .into_shape_clone instead for more flexible reshaping of arrays, which allows copying elements if required.

Errors if the shapes don’t have the same number of elements.
Errors if order RowMajor is given but input is not c-contiguous. Errors if order ColumnMajor is given but input is not f-contiguous.

If shape is not given: use memory layout of incoming array. Row major arrays are reshaped using row major index ordering, column major arrays with column major index ordering.

The new_shape parameter should be a dimension and an optional order like these examples:

(3, 4)                          // Shape 3 x 4 with default order (RowMajor)
((3, 4), Order::RowMajor))      // use specific order
((3, 4), Order::ColumnMajor))   // use specific order
((3, 4), Order::C))             // use shorthand for order - shorthands C and F
§Example
use ndarray::{aview1, aview2};
use ndarray::Order;

assert!(
    aview1(&[1., 2., 3., 4.]).into_shape_with_order((2, 2)).unwrap()
    == aview2(&[[1., 2.],
                [3., 4.]])
);

assert!(
    aview1(&[1., 2., 3., 4.]).into_shape_with_order(((2, 2), Order::ColumnMajor)).unwrap()
    == aview2(&[[1., 3.],
                [2., 4.]])
);
source

pub fn into_shape<E>( self, shape: E, ) -> Result<ArrayBase<S, <E as IntoDimension>::Dim>, ShapeError>
where E: IntoDimension,

👎Deprecated since 0.16.0: Use .into_shape_with_order() or .to_shape()

Transform the array into shape; any shape with the same number of elements is accepted, but the source array or view must be in standard or column-major (Fortran) layout.

Note that .into_shape() “moves” elements differently depending on if the input array is C-contig or F-contig, it follows the index order that corresponds to the memory order. Prefer to use .to_shape() or .into_shape_with_order().

Because of this, the method is deprecated. That reshapes depend on memory order is not intuitive.

Errors if the shapes don’t have the same number of elements.
Errors if the input array is not c- or f-contiguous.

use ndarray::{aview1, aview2};

assert!(
    aview1(&[1., 2., 3., 4.]).into_shape((2, 2)).unwrap()
    == aview2(&[[1., 2.],
                [3., 4.]])
);
source

pub fn into_shape_clone<E>( self, shape: E, ) -> Result<ArrayBase<S, <E as ShapeArg>::Dim>, ShapeError>
where S: DataOwned, A: Clone, E: ShapeArg,

Transform the array into shape; any shape with the same number of elements is accepted. Array elements are reordered in place if possible, otherwise they are copied to create a new array.

If an index ordering is not specified, the default is RowMajor.

§.to_shape vs .into_shape_clone
  • to_shape supports views and outputting views
  • to_shape borrows the original array, into_shape_clone consumes the original
  • into_shape_clone preserves array type (Array vs ArcArray), but does not support views.

Errors if the shapes don’t have the same number of elements.

source

pub fn reshape<E>(&self, shape: E) -> ArrayBase<S, <E as IntoDimension>::Dim>

👎Deprecated since 0.16.0: Use .into_shape_with_order() or .to_shape()

Note: Reshape is for ArcArray only. Use .into_shape_with_order() 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.

This method is obsolete, because it is inflexible in how logical order of the array is handled. See [.to_shape()].

use ndarray::{rcarr1, rcarr2};

assert!(
    rcarr1(&[1., 2., 3., 4.]).reshape((2, 2))
    == rcarr2(&[[1., 2.],
                [3., 4.]])
);
source

pub fn flatten(&self) -> ArrayBase<CowRepr<'_, A>, Dim<[usize; 1]>>
where A: Clone, S: Data,

Flatten the array to a one-dimensional array.

The array is returned as a CowArray; a view if possible, otherwise an owned array.

use ndarray::{arr1, arr3};

let array = arr3(&[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
let flattened = array.flatten();
assert_eq!(flattened, arr1(&[1, 2, 3, 4, 5, 6, 7, 8]));
source

pub fn flatten_with_order( &self, order: Order, ) -> ArrayBase<CowRepr<'_, A>, Dim<[usize; 1]>>
where A: Clone, S: Data,

Flatten the array to a one-dimensional array.

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.

use ndarray::{arr1, arr2};
use ndarray::Order;

let array = arr2(&[[1, 2], [3, 4], [5, 6], [7, 8]]);
let flattened = array.flatten_with_order(Order::RowMajor);
assert_eq!(flattened, arr1(&[1, 2, 3, 4, 5, 6, 7, 8]));
let flattened = array.flatten_with_order(Order::ColumnMajor);
assert_eq!(flattened, arr1(&[1, 3, 5, 7, 2, 4, 6, 8]));
source

pub fn into_flat(self) -> ArrayBase<S, Dim<[usize; 1]>>
where A: Clone, S: DataOwned,

Flatten the array to a one-dimensional array, consuming the array.

If possible, no copy is made, and the new array use the same memory as the original array. Otherwise, a new array is allocated and the elements are copied.

use ndarray::{arr1, arr3};

let array = arr3(&[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
let flattened = array.into_flat();
assert_eq!(flattened, arr1(&[1, 2, 3, 4, 5, 6, 7, 8]));
source

pub fn into_dyn(self) -> ArrayBase<S, Dim<IxDynImpl>>

Convert any array or array view to a dynamic dimensional array or array view (respectively).

use ndarray::{arr2, ArrayD};

let array: ArrayD<i32> = arr2(&[[1, 2],
                                [3, 4]]).into_dyn();
source

pub fn into_dimensionality<D2>(self) -> Result<ArrayBase<S, D2>, ShapeError>
where D2: Dimension,

Convert an array or array view to another with the same type, but different dimensionality type. Errors if the dimensions don’t agree (the number of axes must match).

Note that conversion to a dynamic dimensional array will never fail (and is equivalent to the into_dyn method).

use ndarray::{ArrayD, Ix2, IxDyn};

// Create a dynamic dimensionality array and convert it to an Array2
// (Ix2 dimension type).

let array = ArrayD::<f64>::zeros(IxDyn(&[10, 10]));

assert!(array.into_dimensionality::<Ix2>().is_ok());
source

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])
);
source

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.]])
);
source

pub fn permuted_axes<T>(self, axes: T) -> ArrayBase<S, D>
where T: IntoDimension<Dim = D>,

Permute the axes.

This does not move any data, it just adjusts the array’s dimensions and strides.

i in the j-th place in the axes sequence means self’s i-th axis becomes self.permuted_axes()’s j-th axis

Panics if any of the axes are out of bounds, if an axis is missing, or if an axis is repeated more than once.

§Examples
use ndarray::{arr2, Array3};

let a = arr2(&[[0, 1], [2, 3]]);
assert_eq!(a.view().permuted_axes([1, 0]), a.t());

let b = Array3::<u8>::zeros((1, 2, 3));
assert_eq!(b.permuted_axes([1, 0, 2]).shape(), &[2, 1, 3]);
source

pub fn reversed_axes(self) -> ArrayBase<S, D>

Transpose the array by reversing axes.

Transposition reverses the order of the axes (dimensions and strides) while retaining the same data.

source

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().

source

pub fn axes(&self) -> Axes<'_, D>

Return an iterator over the length and stride of each axis.

source

pub fn max_stride_axis(&self) -> Axis

Return the axis with the greatest stride (by absolute value), preferring axes with len > 1.

source

pub fn invert_axis(&mut self, axis: Axis)

Reverse the stride of axis.

Panics if the axis is out of bounds.

source

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 into axis is the product of the original lengths of the two axes.

  • The new length of the take axis 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.

source

pub fn insert_axis(self, axis: Axis) -> ArrayBase<S, <D as Dimension>::Larger>

Insert new array axis at axis and return the result.

use ndarray::{Array3, Axis, arr1, arr2};

// Convert a 1-D array into a row vector (2-D).
let a = arr1(&[1, 2, 3]);
let row = a.insert_axis(Axis(0));
assert_eq!(row, arr2(&[[1, 2, 3]]));

// Convert a 1-D array into a column vector (2-D).
let b = arr1(&[1, 2, 3]);
let col = b.insert_axis(Axis(1));
assert_eq!(col, arr2(&[[1], [2], [3]]));

// The new axis always has length 1.
let b = Array3::<f64>::zeros((3, 4, 5));
assert_eq!(b.insert_axis(Axis(2)).shape(), &[3, 4, 1, 5]);

Panics if the axis is out of bounds.

source

pub fn remove_axis(self, axis: Axis) -> ArrayBase<S, <D as Dimension>::Smaller>
where D: RemoveAxis,

Remove array axis axis and return the result.

This is equivalent to .index_axis_move(axis, 0) and makes most sense to use if the axis to remove is of length 1.

Panics if the axis is out of bounds or its length is zero.

source

pub fn assign<E, S2>(&mut self, rhs: &ArrayBase<S2, E>)
where E: Dimension, S: DataMut, A: Clone, S2: Data<Elem = A>,

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.

source

pub fn assign_to<P>(&self, to: P)
where S: Data, P: IntoNdProducer<Dim = D>, <P as IntoNdProducer>::Item: AssignElem<A>, A: Clone,

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.

source

pub fn fill(&mut self, x: A)
where S: DataMut, A: Clone,

Perform an elementwise assigment to self from element x.

source

pub fn zip_mut_with<B, S2, E, F>(&mut self, rhs: &ArrayBase<S2, E>, f: F)
where S: DataMut, S2: Data<Elem = B>, E: Dimension, F: FnMut(&mut A, &B),

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.

source

pub fn fold<'a, F, B>(&'a self, init: B, f: F) -> B
where F: FnMut(B, &'a A) -> B, A: 'a, S: Data,

Traverse the array elements and apply a fold, returning the resulting value.

Elements are visited in arbitrary order.

source

pub fn map<'a, B, F>(&'a self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where F: FnMut(&'a A) -> B, A: 'a, S: Data,

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]])
);
source

pub fn map_mut<'a, B, F>(&'a mut self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where F: FnMut(&'a mut A) -> B, A: 'a, S: DataMut,

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.

source

pub fn mapv<B, F>(&self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where F: FnMut(A) -> B, A: Clone, S: Data,

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.]])
);
source

pub fn mapv_into<F>(self, f: F) -> ArrayBase<S, D>
where S: DataMut, F: FnMut(A) -> A, A: Clone,

Call f by value on each element, update the array with the new values and return it.

Elements are visited in arbitrary order.

source

pub fn mapv_into_any<B, F>(self, f: F) -> ArrayBase<OwnedRepr<B>, D>
where S: DataMut, F: FnMut(A) -> B, A: Clone + 'static, B: 'static,

Consume the array, call f by value on each element, and return an owned array with the new values. Works for any F: FnMut(A)->B.

If A and B are the same type then the map is performed by delegating to mapv_into and then converting into an owned array. This avoids unnecessary memory allocations in mapv.

If A and B are different types then a new array is allocated and the map is performed as in mapv.

Elements are visited in arbitrary order.

source

pub fn map_inplace<'a, F>(&'a mut self, f: F)
where S: DataMut, A: 'a, F: FnMut(&'a mut A),

Modify the array in place by calling f by mutable reference on each element.

Elements are visited in arbitrary order.

source

pub fn mapv_inplace<F>(&mut self, f: F)
where S: DataMut, F: FnMut(A) -> A, A: Clone,

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,
);
source

pub fn for_each<'a, F>(&'a self, f: F)
where F: FnMut(&'a A), A: 'a, S: Data,

Call f for each element in the array.

Elements are visited in arbitrary order.

source

pub fn fold_axis<B, F>( &self, axis: Axis, init: B, fold: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
where D: RemoveAxis, F: FnMut(&B, &A) -> B, B: Clone, S: Data,

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.

source

pub fn map_axis<'a, B, F>( &'a self, axis: Axis, mapping: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
where D: RemoveAxis, F: FnMut(ArrayBase<ViewRepr<&'a A>, Dim<[usize; 1]>>) -> B, A: 'a, S: Data,

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.

source

pub fn map_axis_mut<'a, B, F>( &'a mut self, axis: Axis, mapping: F, ) -> ArrayBase<OwnedRepr<B>, <D as Dimension>::Smaller>
where D: RemoveAxis, F: FnMut(ArrayBase<ViewRepr<&'a mut A>, Dim<[usize; 1]>>) -> B, A: 'a, S: DataMut,

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.

source

pub fn remove_index(&mut self, axis: Axis, index: usize)
where S: DataOwned + DataMut,

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).

source

pub fn accumulate_axis_inplace<F>(&mut self, axis: Axis, f: F)
where F: FnMut(&A, &mut A), S: DataMut,

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]],
    ],
);
source§

impl<A, S, D> ArrayBase<S, D>
where S: RawDataSubst<A, Elem = MaybeUninit<A>>, D: Dimension,

Methods specific to arrays with MaybeUninit elements.

See also all methods for ArrayBase

source

pub unsafe fn assume_init(self) -> ArrayBase<<S as RawDataSubst<A>>::Output, D>

Promise that the array’s elements are all fully initialized, and convert the array from element type MaybeUninit<A> to A.

For example, it can convert an Array<MaybeUninit<f64>, D> to Array<f64, D>.

§Safety

Safe to use if all the array’s elements have been initialized.

Note that for owned and shared ownership arrays, the promise must include all of the array’s storage; it is for example possible to slice these in place, but that must only be done after all elements have been initialized.

source§

impl<A, S, D> ArrayBase<S, D>
where S: Data<Elem = A>, D: Dimension,

source

pub fn scaled_add<S2, E>(&mut self, alpha: A, rhs: &ArrayBase<S2, E>)
where S: DataMut, S2: Data<Elem = A>, A: LinalgScalar, E: Dimension,

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.

source§

impl<A, S, D> ArrayBase<S, D>
where A: 'static + PartialOrd + Clone, S: Data<Elem = A>, D: Dimension,

source

pub fn clamp(&self, min: A, max: A) -> ArrayBase<OwnedRepr<A>, D>

Limit the values for each element, similar to NumPy’s clip function.

use ndarray::array;

let a = array![0., 1., 2., 3., 4., 5., 6., 7., 8., 9.];
assert_eq!(a.clamp(1., 8.), array![1., 1., 2., 3., 4., 5., 6., 7., 8., 8.]);
assert_eq!(a.clamp(3., 6.), array![3., 3., 3., 3., 4., 5., 6., 6., 6., 6.]);
§Panics

Panics if !(min <= max).

source§

impl<A, S, D> ArrayBase<S, D>
where A: 'static + Float, S: Data<Elem = A>, D: Dimension,

§Element-wise methods for float arrays

Element-wise math functions for any array type that contains float number.

source

pub fn is_nan(&self) -> ArrayBase<OwnedRepr<bool>, D>

If the number is NaN (not a number), then true is returned for each element.

source

pub fn is_all_nan(&self) -> bool

Return true if all elements are NaN (not a number).

source

pub fn is_any_nan(&self) -> bool

Return true if any element is NaN (not a number).

source

pub fn is_infinite(&self) -> ArrayBase<OwnedRepr<bool>, D>

If the number is infinity, then true is returned for each element.

source

pub fn is_all_infinite(&self) -> bool

Return true if all elements are infinity.

source

pub fn is_any_infinite(&self) -> bool

Return true if any element is infinity.

source

pub fn floor(&self) -> ArrayBase<OwnedRepr<A>, D>

The largest integer less than or equal to each element.

source

pub fn ceil(&self) -> ArrayBase<OwnedRepr<A>, D>

The smallest integer less than or equal to each element.

source

pub fn round(&self) -> ArrayBase<OwnedRepr<A>, D>

The nearest integer of each element.

source

pub fn trunc(&self) -> ArrayBase<OwnedRepr<A>, D>

The integer part of each element.

source

pub fn fract(&self) -> ArrayBase<OwnedRepr<A>, D>

The fractional part of each element.

source

pub fn abs(&self) -> ArrayBase<OwnedRepr<A>, D>

Absolute of each element.

source

pub fn signum(&self) -> ArrayBase<OwnedRepr<A>, D>

Sign number of each element.

  • 1.0 for all positive numbers.
  • -1.0 for all negative numbers.
  • NaN for all NaN (not a number).
source

pub fn recip(&self) -> ArrayBase<OwnedRepr<A>, D>

The reciprocal (inverse) of each element, 1/x.

source

pub fn sqrt(&self) -> ArrayBase<OwnedRepr<A>, D>

Square root of each element.

source

pub fn exp(&self) -> ArrayBase<OwnedRepr<A>, D>

e^x of each element (exponential function).

source

pub fn exp2(&self) -> ArrayBase<OwnedRepr<A>, D>

2^x of each element.

source

pub fn ln(&self) -> ArrayBase<OwnedRepr<A>, D>

Natural logarithm of each element.

source

pub fn log2(&self) -> ArrayBase<OwnedRepr<A>, D>

Base 2 logarithm of each element.

source

pub fn log10(&self) -> ArrayBase<OwnedRepr<A>, D>

Base 10 logarithm of each element.

source

pub fn cbrt(&self) -> ArrayBase<OwnedRepr<A>, D>

Cubic root of each element.

source

pub fn sin(&self) -> ArrayBase<OwnedRepr<A>, D>

Sine of each element (in radians).

source

pub fn cos(&self) -> ArrayBase<OwnedRepr<A>, D>

Cosine of each element (in radians).

source

pub fn tan(&self) -> ArrayBase<OwnedRepr<A>, D>

Tangent of each element (in radians).

source

pub fn to_degrees(&self) -> ArrayBase<OwnedRepr<A>, D>

Converts radians to degrees for each element.

source

pub fn to_radians(&self) -> ArrayBase<OwnedRepr<A>, D>

Converts degrees to radians for each element.

source

pub fn powi(&self, rhs: i32) -> ArrayBase<OwnedRepr<A>, D>

Integer power of each element.

This function is generally faster than using float power.

source

pub fn powf(&self, rhs: A) -> ArrayBase<OwnedRepr<A>, D>

Float power of each element.

source

pub fn log(&self, rhs: A) -> ArrayBase<OwnedRepr<A>, D>

Logarithm of each element with respect to an arbitrary base.

source

pub fn abs_sub(&self, rhs: A) -> ArrayBase<OwnedRepr<A>, D>

The positive difference between given number and each element.

source

pub fn pow2(&self) -> ArrayBase<OwnedRepr<A>, D>

Square (two powers) of each element.

source§

impl<A, S, D> ArrayBase<S, D>
where S: Data<Elem = A>, D: Dimension,

§Numerical Methods for Arrays

source

pub fn sum(&self) -> A
where A: Clone + Add<Output = A> + Zero,

Return the sum of all elements in the array.

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [3., 4.]]);
assert_eq!(a.sum(), 10.);
source

pub fn mean(&self) -> Option<A>
where A: Clone + FromPrimitive + Add<Output = A> + Div<Output = A> + Zero,

Returns the arithmetic mean x̅ of all elements in the array:

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

If the array is empty, None is returned.

Panics if A::from_usize() fails to convert the number of elements in the array.

source

pub fn product(&self) -> A
where A: Clone + Mul<Output = A> + One,

Return the product of all elements in the array.

use ndarray::arr2;

let a = arr2(&[[1., 2.],
               [3., 4.]]);
assert_eq!(a.product(), 24.);
source

pub fn var(&self, ddof: A) -> A
where 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=1

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and 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);
source

pub fn std(&self, ddof: A) -> A
where 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=1

and 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);
source

pub fn sum_axis( &self, axis: Axis, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
where A: Clone + Zero<Output = A> + Add, D: RemoveAxis,

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.

source

pub fn product_axis( &self, axis: Axis, ) -> ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>
where A: Clone + One<Output = A> + Mul, D: RemoveAxis,

Return product along axis.

The product of an empty array is 1.

use ndarray::{aview0, aview1, arr2, Axis};

let a = arr2(&[[1., 2., 3.],
               [4., 5., 6.]]);

assert!(
    a.product_axis(Axis(0)) == aview1(&[4., 10., 18.]) &&
    a.product_axis(Axis(1)) == aview1(&[6., 120.]) &&

    a.product_axis(Axis(0)).product_axis(Axis(0)) == aview0(&720.)
);

Panics if axis is out of bounds.

source

pub fn mean_axis( &self, axis: Axis, ) -> Option<ArrayBase<OwnedRepr<A>, <D as Dimension>::Smaller>>
where A: Clone + Zero<Output = A> + FromPrimitive + Add + Div<Output = A>, D: RemoveAxis,

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)
);
source

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=1

where

    1   n
x̅ = ―   ∑ xᵢ
    n  i=1

and 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.]));
source

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=1

and 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.]));
source§

impl<S, A, D> ArrayBase<S, D>
where S: Data<Elem = A>, D: Dimension, A: Clone + Zero,

source

pub fn triu(&self, k: isize) -> ArrayBase<OwnedRepr<A>, D>

Upper triangular of an array.

Return a copy of the array with elements below the k-th diagonal zeroed. For arrays with ndim exceeding 2, triu will apply to the final two axes. For 0D and 1D arrays, triu will return an unchanged clone.

See also ArrayBase::tril

use ndarray::array;

let arr = array![
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
assert_eq!(
    arr.triu(0),
    array![
        [1, 2, 3],
        [0, 5, 6],
        [0, 0, 9]
    ]
);
source

pub fn tril(&self, k: isize) -> ArrayBase<OwnedRepr<A>, D>

Lower triangular of an array.

Return a copy of the array with elements above the k-th diagonal zeroed. For arrays with ndim exceeding 2, tril will apply to the final two axes. For 0D and 1D arrays, tril will return an unchanged clone.

See also ArrayBase::triu

use ndarray::array;

let arr = array![
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
assert_eq!(
    arr.tril(0),
    array![
        [1, 0, 0],
        [4, 5, 0],
        [7, 8, 9]
    ]
);
source§

impl<A, S> ArrayBase<S, Dim<IxDynImpl>>
where S: Data<Elem = A>,

§Methods for Dynamic-Dimensional Arrays

source

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]);
source

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]);
source

pub fn squeeze(self) -> ArrayBase<S, Dim<IxDynImpl>>

Remove axes of length 1 and return the modified array.

If the array has more the one dimension, the result array will always have at least one dimension, even if it has a length of 1.

use ndarray::{arr1, arr2, arr3};

let a = arr3(&[[[1, 2, 3]], [[4, 5, 6]]]).into_dyn();
assert_eq!(a.shape(), &[2, 1, 3]);
let b = a.squeeze();
assert_eq!(b, arr2(&[[1, 2, 3], [4, 5, 6]]).into_dyn());
assert_eq!(b.shape(), &[2, 3]);

let c = arr2(&[[1]]).into_dyn();
assert_eq!(c.shape(), &[1, 1]);
let d = c.squeeze();
assert_eq!(d, arr1(&[1]).into_dyn());
assert_eq!(d.shape(), &[1]);
source§

impl<'a, A, D> ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

Methods for read-only array views.

source

pub fn from_shape<Sh>( shape: Sh, xs: &'a [A], ) -> Result<ArrayBase<ViewRepr<&'a A>, D>, ShapeError>
where 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;

// advanced example where we are even specifying exact strides to use (which is optional).
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]);
source

pub unsafe fn from_shape_ptr<Sh>( shape: Sh, ptr: *const A, ) -> ArrayBase<ViewRepr<&'a A>, D>
where Sh: Into<StrideShape<D>>,

Create an ArrayView<A, D> from shape information and a raw pointer to the elements.

§Safety

The caller is responsible for ensuring all of the following:

  • The elements seen by moving ptr according to the shape and strides must live at least as long as 'a and must not be not mutably aliased for the duration of 'a.

  • ptr must be non-null and aligned, and it must be safe to .offset() ptr by zero.

  • It must be safe to .offset() the pointer repeatedly along all axes and calculate the counts for the .offset() calls without overflow, even if the array is empty or the elements are zero-sized.

    In other words,

    • All possible pointers generated by moving along all axes must be in bounds or one byte past the end of a single allocation with element type A. The only exceptions are if the array is empty or the element type is zero-sized. In these cases, ptr may be dangling, but it must still be safe to .offset() the pointer along the axes.

    • The offset in units of bytes between the least address and greatest address by moving along all axes must not exceed isize::MAX. This constraint prevents the computed offset, in bytes, from overflowing isize regardless of the starting point due to past offsets.

    • The offset in units of A between the least address and greatest address by moving along all axes must not exceed isize::MAX. This constraint prevents overflow when calculating the count parameter to .offset() regardless of the starting point due to past offsets.

  • The product of non-zero axis lengths must not exceed isize::MAX.

  • Strides must be non-negative.

This function can use debug assertions to check some of these requirements, but it’s not a complete check.

source§

impl<'a, A, D> ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

Methods for read-only array views.

source

pub fn reborrow<'b>(self) -> ArrayBase<ViewRepr<&'b A>, D>
where 'a: 'b,

Convert the view into an ArrayView<'b, A, D> where 'b is a lifetime outlived by 'a'.

source

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.

source

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.

source§

impl<'a, A, D> ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

Methods for read-only array views.

source

pub fn split_at( self, axis: Axis, index: usize, ) -> (ArrayBase<ViewRepr<&'a A>, D>, ArrayBase<ViewRepr<&'a A>, D>)

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.

Examples:

let a = aview2(&[[0, 1, 2, 3],
                 [4, 5, 6, 7],
                 [8, 9, 0, 1]]);

The array view a has two axes and shape 3 × 4:

         ──▶ Axis(1)
        ┌─────┬─────┬─────┬─────┐ 0
      │ │ a₀₀ │ a₀₁ │ a₀₂ │ a₀₃ │
      ▼ ├─────┼─────┼─────┼─────┤ 1
 Axis(0)│ a₁₀ │ a₁₁ │ a₁₂ │ a₁₃ │
        ├─────┼─────┼─────┼─────┤ 2
        │ a₂₀ │ a₂₁ │ a₂₂ │ a₂₃ │
        └─────┴─────┴─────┴─────┘ 3 ↑
        0     1     2     3     4 ← possible split_at indices.

Row indices increase along Axis(0), and column indices increase along Axis(1). Note that we split “before” an element index, and that both 0 and the endpoint are valid split indices.

Example 1: Split a along the first axis, in this case the rows, at index 2.
This produces views v1 and v2 of shapes 2 × 4 and 1 × 4:

let (v1, v2) = a.split_at(Axis(0), 2);
        ┌─────┬─────┬─────┬─────┐       0  ↓ indices
        │ a₀₀ │ a₀₁ │ a₀₂ │ a₀₃ │            along Axis(0)
        ├─────┼─────┼─────┼─────┤ v1    1
        │ a₁₀ │ a₁₁ │ a₁₂ │ a₁₃ │
        └─────┴─────┴─────┴─────┘
        ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄       2
        ┌─────┬─────┬─────┬─────┐
        │ a₂₀ │ a₂₁ │ a₂₂ │ a₂₃ │ v2
        └─────┴─────┴─────┴─────┘       3

Example 2: Split a along the second axis, in this case the columns, at index 2.
This produces views u1 and u2 of shapes 3 × 2 and 3 × 2:

let (u1, u2) = a.split_at(Axis(1), 2);
             u1             u2
        ┌─────┬─────┐┊┌─────┬─────┐
        │ a₀₀ │ a₀₁ │┊│ a₀₂ │ a₀₃ │
        ├─────┼─────┤┊├─────┼─────┤
        │ a₁₀ │ a₁₁ │┊│ a₁₂ │ a₁₃ │
        ├─────┼─────┤┊├─────┼─────┤
        │ a₂₀ │ a₂₁ │┊│ a₂₂ │ a₂₃ │
        └─────┴─────┘┊└─────┴─────┘
        0     1      2      3     4  indices →
                                     along Axis(1)
source§

impl<'a, T, D> ArrayBase<ViewRepr<&'a Complex<T>>, D>
where D: Dimension,

source

pub fn split_complex(self) -> Complex<ArrayBase<ViewRepr<&'a T>, D>>

Splits the view into views of the real and imaginary components of the elements.

use ndarray::prelude::*;
use num_complex::{Complex, Complex64};

let arr = array![
    [Complex64::new(1., 2.), Complex64::new(3., 4.)],
    [Complex64::new(5., 6.), Complex64::new(7., 8.)],
    [Complex64::new(9., 10.), Complex64::new(11., 12.)],
];
let Complex { re, im } = arr.view().split_complex();
assert_eq!(re, array![[1., 3.], [5., 7.], [9., 11.]]);
assert_eq!(im, array![[2., 4.], [6., 8.], [10., 12.]]);
source§

impl<A, S, D> ArrayBase<S, D>
where S: Data<Elem = A>, D: Dimension,

This impl block contains no items.

Private Methods

source§

impl<'a, A, D> ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

This impl block contains no items.

Private array view methods

source§

impl<'a, A, D> ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

This impl block contains no items.

Private array view methods

Trait Implementations

source§

impl<'a, A, B, S, S2, D, E> Add<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Add<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise addition between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the + operator.
source§

fn add( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Add<&'a ArrayBase<S2, E>>>::Output

Performs the + operation. Read more
source§

impl<A, B, S, S2, D, E> Add<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Add<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise addition between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the + operator.
source§

fn add( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Add<ArrayBase<S2, E>>>::Output

Performs the + operation. Read more
source§

impl<A, S, D, B> Add<B> for ArrayBase<S, D>
where A: Clone + Add<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise addition between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the + operator.
source§

fn add(self, x: B) -> ArrayBase<S, D>

Performs the + operation. Read more
source§

impl<'a, A, S, S2, D, E> AddAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + AddAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self += rhs as elementwise addition (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn add_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the += operation. Read more
source§

impl<A, S, D> AddAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + AddAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self += rhs as elementwise addition (in place).

source§

fn add_assign(&mut self, rhs: A)

Performs the += operation. Read more
source§

impl<A, S, D> Binary for ArrayBase<S, D>
where A: Binary, D: Dimension, S: Data<Elem = A>,

Format the array using Binary and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a, A, B, S, S2, D, E> BitAnd<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitAnd<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit and between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the & operator.
source§

fn bitand( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitAnd<&'a ArrayBase<S2, E>>>::Output

Performs the & operation. Read more
source§

impl<A, B, S, S2, D, E> BitAnd<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitAnd<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit and between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the & operator.
source§

fn bitand( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitAnd<ArrayBase<S2, E>>>::Output

Performs the & operation. Read more
source§

impl<A, S, D, B> BitAnd<B> for ArrayBase<S, D>
where A: Clone + BitAnd<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise bit and between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the & operator.
source§

fn bitand(self, x: B) -> ArrayBase<S, D>

Performs the & operation. Read more
source§

impl<'a, A, S, S2, D, E> BitAndAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitAndAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self &= rhs as elementwise bit and (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn bitand_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the &= operation. Read more
source§

impl<A, S, D> BitAndAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + BitAndAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self &= rhs as elementwise bit and (in place).

source§

fn bitand_assign(&mut self, rhs: A)

Performs the &= operation. Read more
source§

impl<'a, A, B, S, S2, D, E> BitOr<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitOr<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit or between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the | operator.
source§

fn bitor( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitOr<&'a ArrayBase<S2, E>>>::Output

Performs the | operation. Read more
source§

impl<A, B, S, S2, D, E> BitOr<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitOr<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit or between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the | operator.
source§

fn bitor( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitOr<ArrayBase<S2, E>>>::Output

Performs the | operation. Read more
source§

impl<A, S, D, B> BitOr<B> for ArrayBase<S, D>
where A: Clone + BitOr<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise bit or between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the | operator.
source§

fn bitor(self, x: B) -> ArrayBase<S, D>

Performs the | operation. Read more
source§

impl<'a, A, S, S2, D, E> BitOrAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitOrAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self |= rhs as elementwise bit or (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn bitor_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the |= operation. Read more
source§

impl<A, S, D> BitOrAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + BitOrAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self |= rhs as elementwise bit or (in place).

source§

fn bitor_assign(&mut self, rhs: A)

Performs the |= operation. Read more
source§

impl<'a, A, B, S, S2, D, E> BitXor<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitXor<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit xor between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the ^ operator.
source§

fn bitxor( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitXor<&'a ArrayBase<S2, E>>>::Output

Performs the ^ operation. Read more
source§

impl<A, B, S, S2, D, E> BitXor<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitXor<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise bit xor between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the ^ operator.
source§

fn bitxor( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as BitXor<ArrayBase<S2, E>>>::Output

Performs the ^ operation. Read more
source§

impl<A, S, D, B> BitXor<B> for ArrayBase<S, D>
where A: Clone + BitXor<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise bit xor between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, x: B) -> ArrayBase<S, D>

Performs the ^ operation. Read more
source§

impl<'a, A, S, S2, D, E> BitXorAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + BitXorAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self ^= rhs as elementwise bit xor (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn bitxor_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the ^= operation. Read more
source§

impl<A, S, D> BitXorAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + BitXorAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self ^= rhs as elementwise bit xor (in place).

source§

fn bitxor_assign(&mut self, rhs: A)

Performs the ^= operation. Read more
source§

impl<S, D> Clone for ArrayBase<S, D>
where S: RawDataClone, D: Clone,

source§

fn clone_from(&mut self, other: &ArrayBase<S, D>)

Array implements .clone_from() to reuse an array’s existing allocation. Semantically equivalent to *self = other.clone(), but potentially more efficient.

source§

fn clone(&self) -> ArrayBase<S, D>

Returns a copy of the value. Read more
source§

impl<A, S, D> Debug for ArrayBase<S, D>
where A: Debug, D: Dimension, S: Data<Elem = A>,

Format the array using Debug and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<A, S, D> Default for ArrayBase<S, D>
where S: DataOwned<Elem = A>, D: Dimension, A: Default,

Create an owned array with a default state.

The array is created with dimension D::default(), which results in for example dimensions 0 and (0, 0) with zero elements for the one-dimensional and two-dimensional cases respectively.

The default dimension for IxDyn is IxDyn(&[0]) (array has zero elements). And the default for the dimension () is () (array has one element).

Since arrays cannot grow, the intention is to use the default value as placeholder.

source§

fn default() -> ArrayBase<S, D>

Returns the “default value” for a type. Read more
source§

impl<A, S, D> Display for ArrayBase<S, D>
where A: Display, D: Dimension, S: Data<Elem = A>,

Format the array using Display and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a, A, B, S, S2, D, E> Div<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Div<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise division between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the / operator.
source§

fn div( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Div<&'a ArrayBase<S2, E>>>::Output

Performs the / operation. Read more
source§

impl<A, B, S, S2, D, E> Div<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Div<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise division between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the / operator.
source§

fn div( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Div<ArrayBase<S2, E>>>::Output

Performs the / operation. Read more
source§

impl<A, S, D, B> Div<B> for ArrayBase<S, D>
where A: Clone + Div<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise division between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the / operator.
source§

fn div(self, x: B) -> ArrayBase<S, D>

Performs the / operation. Read more
source§

impl<'a, A, S, S2, D, E> DivAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + DivAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self /= rhs as elementwise division (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn div_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the /= operation. Read more
source§

impl<A, S, D> DivAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + DivAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self /= rhs as elementwise division (in place).

source§

fn div_assign(&mut self, rhs: A)

Performs the /= operation. Read more
source§

impl<'a, A, S, D> From<&'a ArrayBase<S, D>> for ArrayBase<ViewRepr<&'a A>, D>
where S: Data<Elem = A>, D: Dimension,

Implementation of ArrayView::from(&A) where A is an array.

source§

fn from(array: &'a ArrayBase<S, D>) -> ArrayBase<ViewRepr<&'a A>, D>

Create a read-only array view of the array.

source§

impl<S, D> Hash for ArrayBase<S, D>
where D: Dimension, S: Data, <S as RawData>::Elem: Hash,

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<S, D, I> Index<I> for ArrayBase<S, D>
where D: Dimension, I: NdIndex<D>, S: Data,

Access the element at index.

Panics if index is out of bounds.

§

type Output = <S as RawData>::Elem

The returned type after indexing.
source§

fn index(&self, index: I) -> &<S as RawData>::Elem

Performs the indexing (container[index]) operation. Read more
source§

impl<S, D, I> IndexMut<I> for ArrayBase<S, D>
where D: Dimension, I: NdIndex<D>, S: DataMut,

Access the element at index mutably.

Panics if index is out of bounds.

source§

fn index_mut(&mut self, index: I) -> &mut <S as RawData>::Elem

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a, A, D> IntoIterator for ArrayBase<ViewRepr<&'a A>, D>
where 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?
source§

fn into_iter(self) -> <ArrayBase<ViewRepr<&'a A>, D> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<A, S, D> LowerExp for ArrayBase<S, D>
where A: LowerExp, D: Dimension, S: Data<Elem = A>,

Format the array using LowerExp and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<A, S, D> LowerHex for ArrayBase<S, D>
where A: LowerHex, D: Dimension, S: Data<Elem = A>,

Format the array using LowerHex and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a, A, B, S, S2, D, E> Mul<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Mul<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise multiplication between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the * operator.
source§

fn mul( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Mul<&'a ArrayBase<S2, E>>>::Output

Performs the * operation. Read more
source§

impl<A, B, S, S2, D, E> Mul<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Mul<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise multiplication between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the * operator.
source§

fn mul( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Mul<ArrayBase<S2, E>>>::Output

Performs the * operation. Read more
source§

impl<A, S, D, B> Mul<B> for ArrayBase<S, D>
where A: Clone + Mul<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise multiplication between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the * operator.
source§

fn mul(self, x: B) -> ArrayBase<S, D>

Performs the * operation. Read more
source§

impl<'a, A, S, S2, D, E> MulAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + MulAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self *= rhs as elementwise multiplication (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn mul_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the *= operation. Read more
source§

impl<A, S, D> MulAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + MulAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self *= rhs as elementwise multiplication (in place).

source§

fn mul_assign(&mut self, rhs: A)

Performs the *= operation. Read more
source§

impl<'a, A, D> NdProducer for ArrayBase<ViewRepr<&'a A>, D>
where D: Dimension,

§

type Item = &'a A

The element produced per iteration.
§

type Dim = D

Dimension type
source§

fn raw_dim(&self) -> <ArrayBase<ViewRepr<&'a A>, D> as NdProducer>::Dim

Return the shape of the producer.
source§

impl<A, S, D> Neg for ArrayBase<S, D>
where A: Clone + Neg<Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension,

source§

fn neg(self) -> ArrayBase<S, D>

Perform an elementwise negation of self and return the result.

§

type Output = ArrayBase<S, D>

The resulting type after applying the - operator.
source§

impl<A, S, D> Not for ArrayBase<S, D>
where A: Clone + Not<Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension,

source§

fn not(self) -> ArrayBase<S, D>

Perform an elementwise unary not of self and return the result.

§

type Output = ArrayBase<S, D>

The resulting type after applying the ! operator.
source§

impl<'a, A, B, S, S2, D> PartialEq<&'a ArrayBase<S2, D>> for ArrayBase<S, D>
where A: PartialEq<B>, S: Data<Elem = A>, S2: Data<Elem = B>, D: Dimension,

Return true if the array shapes and all elements of self and rhs are equal. Return false otherwise.

source§

fn eq(&self, rhs: &&ArrayBase<S2, D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<A, B, S, S2, D> PartialEq<ArrayBase<S2, D>> for ArrayBase<S, D>
where A: PartialEq<B>, S: Data<Elem = A>, S2: Data<Elem = B>, D: Dimension,

Return true if the array shapes and all elements of self and rhs are equal. Return false otherwise.

source§

fn eq(&self, rhs: &ArrayBase<S2, D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, A, B, S, S2, D, E> Rem<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Rem<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise remainder between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the % operator.
source§

fn rem( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Rem<&'a ArrayBase<S2, E>>>::Output

Performs the % operation. Read more
source§

impl<A, B, S, S2, D, E> Rem<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Rem<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise remainder between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the % operator.
source§

fn rem( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Rem<ArrayBase<S2, E>>>::Output

Performs the % operation. Read more
source§

impl<A, S, D, B> Rem<B> for ArrayBase<S, D>
where A: Clone + Rem<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise remainder between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the % operator.
source§

fn rem(self, x: B) -> ArrayBase<S, D>

Performs the % operation. Read more
source§

impl<'a, A, S, S2, D, E> RemAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + RemAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self %= rhs as elementwise remainder (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn rem_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the %= operation. Read more
source§

impl<A, S, D> RemAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + RemAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self %= rhs as elementwise remainder (in place).

source§

fn rem_assign(&mut self, rhs: A)

Performs the %= operation. Read more
source§

impl<'a, A, B, S, S2, D, E> Shl<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Shl<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise left shift between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the << operator.
source§

fn shl( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Shl<&'a ArrayBase<S2, E>>>::Output

Performs the << operation. Read more
source§

impl<A, B, S, S2, D, E> Shl<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Shl<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise left shift between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the << operator.
source§

fn shl( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Shl<ArrayBase<S2, E>>>::Output

Performs the << operation. Read more
source§

impl<A, S, D, B> Shl<B> for ArrayBase<S, D>
where A: Clone + Shl<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise left shift between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the << operator.
source§

fn shl(self, x: B) -> ArrayBase<S, D>

Performs the << operation. Read more
source§

impl<'a, A, S, S2, D, E> ShlAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + ShlAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self <<= rhs as elementwise left shift (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn shl_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the <<= operation. Read more
source§

impl<A, S, D> ShlAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + ShlAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self <<= rhs as elementwise left shift (in place).

source§

fn shl_assign(&mut self, rhs: A)

Performs the <<= operation. Read more
source§

impl<'a, A, B, S, S2, D, E> Shr<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Shr<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise right shift between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the >> operator.
source§

fn shr( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Shr<&'a ArrayBase<S2, E>>>::Output

Performs the >> operation. Read more
source§

impl<A, B, S, S2, D, E> Shr<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Shr<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise right shift between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the >> operator.
source§

fn shr( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Shr<ArrayBase<S2, E>>>::Output

Performs the >> operation. Read more
source§

impl<A, S, D, B> Shr<B> for ArrayBase<S, D>
where A: Clone + Shr<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise right shift between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the >> operator.
source§

fn shr(self, x: B) -> ArrayBase<S, D>

Performs the >> operation. Read more
source§

impl<'a, A, S, S2, D, E> ShrAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + ShrAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self >>= rhs as elementwise right shift (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn shr_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the >>= operation. Read more
source§

impl<A, S, D> ShrAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + ShrAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self >>= rhs as elementwise right shift (in place).

source§

fn shr_assign(&mut self, rhs: A)

Performs the >>= operation. Read more
source§

impl<'a, A, B, S, S2, D, E> Sub<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Sub<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise subtraction between self and reference rhs, and return the result.

rhs must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape, cloning the data if needed.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the - operator.
source§

fn sub( self, rhs: &ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Sub<&'a ArrayBase<S2, E>>>::Output

Performs the - operation. Read more
source§

impl<A, B, S, S2, D, E> Sub<ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + Sub<B, Output = A>, B: Clone, S: DataOwned<Elem = A> + DataMut, S2: Data<Elem = B>, D: Dimension + DimMax<E>, E: Dimension,

Perform elementwise subtraction between self and rhs, and return the result.

self must be an Array or ArcArray.

If their shapes disagree, self is broadcast to their broadcast shape.

Panics if broadcasting isn’t possible.

§

type Output = ArrayBase<S, <D as DimMax<E>>::Output>

The resulting type after applying the - operator.
source§

fn sub( self, rhs: ArrayBase<S2, E>, ) -> <ArrayBase<S, D> as Sub<ArrayBase<S2, E>>>::Output

Performs the - operation. Read more
source§

impl<A, S, D, B> Sub<B> for ArrayBase<S, D>
where A: Clone + Sub<B, Output = A>, S: DataOwned<Elem = A> + DataMut, D: Dimension, B: ScalarOperand,

Perform elementwise subtraction between self and the scalar x, and return the result (based on self).

self must be an Array or ArcArray.

§

type Output = ArrayBase<S, D>

The resulting type after applying the - operator.
source§

fn sub(self, x: B) -> ArrayBase<S, D>

Performs the - operation. Read more
source§

impl<'a, A, S, S2, D, E> SubAssign<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
where A: Clone + SubAssign, S: DataMut<Elem = A>, S2: Data<Elem = A>, D: Dimension, E: Dimension,

Perform self -= rhs as elementwise subtraction (in place). If their shapes disagree, rhs is broadcast to the shape of self.

Panics if broadcasting isn’t possible.

source§

fn sub_assign(&mut self, rhs: &ArrayBase<S2, E>)

Performs the -= operation. Read more
source§

impl<A, S, D> SubAssign<A> for ArrayBase<S, D>
where A: ScalarOperand + SubAssign, S: DataMut<Elem = A>, D: Dimension,

Perform self -= rhs as elementwise subtraction (in place).

source§

fn sub_assign(&mut self, rhs: A)

Performs the -= operation. Read more
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a f16>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a f16>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a f16>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a f32>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a f32>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a f32>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a f64>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a f64>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a f64>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a i16>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a i16>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a i16>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a i32>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a i32>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a i32>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a i64>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a i64>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a i64>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a i8>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a i8>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a i8>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a u16>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a u16>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a u16>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a u32>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a u32>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a u32>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a u64>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a u64>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a u64>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a TensorData> for ArrayBase<ViewRepr<&'a u8>, Dim<IxDynImpl>>

§

type Error = TensorCastError

The type returned in the event of a conversion error.
source§

fn try_from( value: &'a TensorData, ) -> Result<ArrayBase<ViewRepr<&'a u8>, Dim<IxDynImpl>>, <ArrayBase<ViewRepr<&'a u8>, Dim<IxDynImpl>> as TryFrom<&'a TensorData>>::Error>

Performs the conversion.
source§

impl<A, S, D> UpperExp for ArrayBase<S, D>
where A: UpperExp, D: Dimension, S: Data<Elem = A>,

Format the array using UpperExp and apply the formatting parameters used to each element.

The array is shown in multiline style.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<S, D> Copy for ArrayBase<S, D>
where S: RawDataClone + Copy, D: Copy,

source§

impl<S, D> Eq for ArrayBase<S, D>
where D: Dimension, S: Data, <S as RawData>::Elem: Eq,

source§

impl<S, D> Send for ArrayBase<S, D>
where S: Send + Data, D: Send,

ArrayBase is Send when the storage type is.

source§

impl<S, D> Sync for ArrayBase<S, D>
where S: Sync + Data, D: Sync,

ArrayBase is Sync when the storage type is.