Trait arr_rs::core::operations::joining::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§
sourcefn concatenate(
arrs: Vec<Array<T>>,
axis: Option<usize>
) -> Result<Array<T>, ArrayError>
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 concatenateaxis
- 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());
sourcefn stack(
arrs: Vec<Array<T>>,
axis: Option<usize>
) -> Result<Array<T>, ArrayError>
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 stackaxis
- 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());
sourcefn vstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>
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());
sourcefn hstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>
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());
sourcefn dstack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>
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());
sourcefn column_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>
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());
sourcefn row_stack(arrs: Vec<Array<T>>) -> Result<Array<T>, ArrayError>
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());