Trait ArrayJoining

Source
pub trait ArrayJoining<T: ArrayElement>
where Self: Sized + Clone,
{ // Required methods fn concatenate( arrs: Vec<Array<T>>, axis: Option<usize>, ) -> Result<Array<T>, ArrayError>; fn stack( arrs: Vec<Array<T>>, axis: Option<usize>, ) -> Result<Array<T>, ArrayError>; fn vstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>; fn hstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>; fn dstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>; fn column_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>; fn row_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>; }
Expand description

ArrayTrait - Array Joining functions

Required Methods§

Source

fn concatenate( arrs: Vec<Array<T>>, axis: Option<usize>, ) -> Result<Array<T>, ArrayError>

Join a sequence of arrays along an existing axis

§Arguments
  • arrs - arrays to concatenate
  • axis - the axis along which to concat. optional, if None - arrays are flattened
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [1, 2, 3, 4, 5, 6]).unwrap();
assert_eq!(expected, Array::<i32>::concatenate(vec![arr, other], None).unwrap());

let arr = array!(i32, [[1, 2], [3, 4]]).unwrap();
let other = array!(i32, [[5, 6]]).unwrap();
let expected = array!(i32, [[1, 2], [3, 4], [5, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::concatenate(vec![arr, other], Some(0)).unwrap());
§Errors

may returns ArrayError

Source

fn stack( arrs: Vec<Array<T>>, axis: Option<usize>, ) -> Result<Array<T>, ArrayError>

Join a sequence of arrays along a new axis

§Arguments
  • arrs - arrays to stack
  • axis - the axis along which to concat. optional, defaults to 0
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [[1, 2, 3], [4, 5, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::stack(vec![arr, other], None).unwrap());

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

may returns ArrayError

Source

fn vstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>

Stack arrays in sequence vertically (row wise)

§Arguments
  • arrs - arrays to stack
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [[1, 2, 3], [4, 5, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::vstack(vec![arr, other]).unwrap());

let arr = array!(i32, [[1], [2], [3]]).unwrap();
let other = array!(i32, [[4], [5], [6]]).unwrap();
let expected = array!(i32, [[1], [2], [3], [4], [5], [6]]).unwrap();
assert_eq!(expected, Array::<i32>::vstack(vec![arr, other]).unwrap());
§Errors

may returns ArrayError

Source

fn hstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>

Stack arrays in sequence horizontally (column wise)

§Arguments
  • arrs - arrays to stack
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [1, 2, 3, 4, 5, 6]).unwrap();
assert_eq!(expected, Array::<i32>::hstack(vec![arr, other]).unwrap());

let arr = array!(i32, [[1], [2], [3]]).unwrap();
let other = array!(i32, [[4], [5], [6]]).unwrap();
let expected = array!(i32, [[1, 4], [2, 5], [3, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::hstack(vec![arr, other]).unwrap());
§Errors

may returns ArrayError

Source

fn dstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>

Stack arrays in sequence depth wise (along third axis)

§Arguments
  • arrs - arrays to stack
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [[[1, 4], [2, 5], [3, 6]]]).unwrap();
assert_eq!(expected, Array::<i32>::dstack(vec![arr, other]).unwrap());

let arr = array!(i32, [[1], [2], [3]]).unwrap();
let other = array!(i32, [[4], [5], [6]]).unwrap();
let expected = array!(i32, [[[1, 4]], [[2, 5]], [[3, 6]]]).unwrap();
assert_eq!(expected, Array::<i32>::dstack(vec![arr, other]).unwrap());
§Errors

may returns ArrayError

Source

fn column_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>

Stack 1d or 2d arrays as columns into a 2d array row_stack is an alias for vstack

§Arguments
  • arrs - arrays to stack
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [[1, 4], [2, 5], [3, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::column_stack(vec![arr, other]).unwrap());
§Errors

may returns ArrayError

Source

fn row_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>

Stack arrays in sequence vertically (row wise)

§Arguments
  • arrs - arrays to stack
§Examples
use arr_rs::prelude::*;

let arr = array!(i32, [1, 2, 3]).unwrap();
let other = array!(i32, [4, 5, 6]).unwrap();
let expected = array!(i32, [[1, 2, 3], [4, 5, 6]]).unwrap();
assert_eq!(expected, Array::<i32>::row_stack(vec![arr, other]).unwrap());

let arr = array!(i32, [[1], [2], [3]]).unwrap();
let other = array!(i32, [[4], [5], [6]]).unwrap();
let expected = array!(i32, [[1], [2], [3], [4], [5], [6]]).unwrap();
assert_eq!(expected, Array::<i32>::row_stack(vec![arr, other]).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.

Implementors§