Trait ArrayAxis

Source
pub trait ArrayAxis<T: ArrayElement>
where Array<T>: Sized + Clone,
{ // Required methods fn apply_along_axis<S: ArrayElement, F>( &self, axis: usize, f: F, ) -> Result<Array<S>, ArrayError> where F: FnMut(&Array<T>) -> Result<Array<S>, ArrayError>; fn transpose( &self, axes: Option<Vec<isize>>, ) -> Result<Array<T>, ArrayError>; fn moveaxis( &self, source: Vec<isize>, destination: Vec<isize>, ) -> Result<Array<T>, ArrayError>; fn rollaxis( &self, axis: isize, start: Option<isize>, ) -> Result<Array<T>, ArrayError>; fn swapaxes( &self, axis: isize, start: isize, ) -> Result<Array<T>, ArrayError>; fn expand_dims(&self, axes: Vec<isize>) -> Result<Array<T>, ArrayError>; fn squeeze(&self, axes: Option<Vec<isize>>) -> Result<Array<T>, ArrayError>; }
Expand description

ArrayTrait - Array Axis functions

Required Methods§

Source

fn apply_along_axis<S: ArrayElement, F>( &self, axis: usize, f: F, ) -> Result<Array<S>, ArrayError>
where F: FnMut(&Array<T>) -> Result<Array<S>, ArrayError>,

Applies given function along an axis

§Arguments
  • axis - axis along which the function will be applied
  • f - function to apply
§Errors

may returns ArrayError

Source

fn transpose(&self, axes: Option<Vec<isize>>) -> Result<Array<T>, ArrayError>

Returns an array with axes transposed

§Arguments
  • axes - if defined, it’s a list of axes to be included in transposition
§Examples
use arr_rs::prelude::*;

let arr = Array::new(vec![1,2,3,4,5,6,7,8], vec![2, 4]).unwrap();
assert_eq!(array!(i32, [[1, 5], [2, 6], [3, 7], [4, 8]]), arr.transpose(None));

let arr = Array::new(vec![1,2,3,4,5,6,7,8], vec![4, 2]).unwrap();
assert_eq!(array!(i32, [[1, 3, 5, 7], [2, 4, 6, 8]]), arr.transpose(None));

let arr = Array::new(vec![1,2,3,4,5,6,7,8], vec![4, 2]).unwrap();
assert_eq!(array!(i32, [[1, 3, 5, 7], [2, 4, 6, 8]]), arr.transpose(Some(vec![1, 0])));
§Errors

may returns ArrayError

Source

fn moveaxis( &self, source: Vec<isize>, destination: Vec<isize>, ) -> Result<Array<T>, ArrayError>

Move axes of an array to new positions

§Arguments
  • source - original positions of the axes to move. must be unique
  • destination - destination positions for each of the original axes. must be unique
§Examples
use arr_rs::prelude::*;

let arr = Array::<i32>::zeros(vec![3, 4, 5]);
assert_eq!(vec![4, 5, 3], arr.moveaxis(vec![0], vec![2]).get_shape().unwrap());
assert_eq!(vec![5, 3, 4], arr.moveaxis(vec![2], vec![0]).get_shape().unwrap());
§Errors

may returns ArrayError

Source

fn rollaxis( &self, axis: isize, start: Option<isize>, ) -> Result<Array<T>, ArrayError>

Roll the specified axis backwards, until it lies in a given position

§Arguments
  • axis - the axis to be rolled
  • start - start position. optional, defaults to 0
§Examples
use arr_rs::prelude::*;

let arr = Array::<i32>::zeros(vec![3, 4, 5]);
assert_eq!(vec![4, 3, 5], arr.rollaxis(1, None).get_shape().unwrap());
assert_eq!(vec![3, 5, 4], arr.rollaxis(2, Some(1)).get_shape().unwrap());
§Errors

may returns ArrayError

Source

fn swapaxes(&self, axis: isize, start: isize) -> Result<Array<T>, ArrayError>

Interchange two axes of an array

§Arguments
  • axis_1 - first axis
  • axis_1 - second axis
§Examples
use arr_rs::prelude::*;

let arr = Array::<i32>::zeros(vec![3, 4, 5]);
assert_eq!(vec![5, 4, 3], arr.swapaxes(0, 2).get_shape().unwrap());
assert_eq!(vec![3, 5, 4], arr.swapaxes(2, 1).get_shape().unwrap());
§Errors

may returns ArrayError

Source

fn expand_dims(&self, axes: Vec<isize>) -> Result<Array<T>, ArrayError>

Expand the shape of an array

§Arguments
  • axes - position in the expanded axes where the new axis (or axes) is placed
§Examples
use arr_rs::prelude::*;

let arr = Array::<i32>::zeros(vec![3, 4, 5]);
assert_eq!(vec![1, 3, 4, 5], arr.expand_dims(vec![0]).get_shape().unwrap());
assert_eq!(vec![3, 1, 4, 1, 5], arr.expand_dims(vec![1, 3]).get_shape().unwrap());
§Errors

may returns ArrayError

Source

fn squeeze(&self, axes: Option<Vec<isize>>) -> Result<Array<T>, ArrayError>

Remove axes of length one from array

§Arguments
  • axes - position of the 10-sized axes to remove. if None, all such axes will be removed
§Examples
use arr_rs::prelude::*;

let arr = Array::<i32>::zeros(vec![1, 3, 1, 4, 5]);
assert_eq!(vec![3, 4, 5], arr.squeeze(None).get_shape().unwrap());
assert_eq!(vec![3, 1, 4, 5], arr.squeeze(Some(vec![0])).get_shape().unwrap());
assert_eq!(vec![1, 3, 4, 5], arr.squeeze(Some(vec![2])).get_shape().unwrap());
§Errors

may returns ArrayError

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: ArrayElement> ArrayAxis<T> for Result<Array<T>, ArrayError>

Source§

fn apply_along_axis<S: ArrayElement, F>( &self, axis: usize, f: F, ) -> Result<Array<S>, ArrayError>
where F: FnMut(&Array<T>) -> Result<Array<S>, ArrayError>,

Source§

fn transpose(&self, axes: Option<Vec<isize>>) -> Self

Source§

fn moveaxis(&self, source: Vec<isize>, destination: Vec<isize>) -> Self

Source§

fn rollaxis(&self, axis: isize, start: Option<isize>) -> Self

Source§

fn swapaxes(&self, axis: isize, start: isize) -> Self

Source§

fn expand_dims(&self, axes: Vec<isize>) -> Self

Source§

fn squeeze(&self, axes: Option<Vec<isize>>) -> Self

Implementors§