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

Implementors§