Trait arr_rs::core::operations::split::ArraySplit
source · pub trait ArraySplit<T: ArrayElement>where
Self: Sized + Clone,{
// Required methods
fn array_split(
&self,
parts: usize,
axis: Option<usize>
) -> Result<Vec<Array<T>>, ArrayError>;
fn split(
&self,
parts: usize,
axis: Option<usize>
) -> Result<Vec<Array<T>>, ArrayError>;
fn split_axis(&self, axis: usize) -> Result<Vec<Array<T>>, ArrayError>;
fn hsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>;
fn vsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>;
fn dsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>;
}
Expand description
ArrayTrait - Array Split functions
Required Methods§
sourcefn array_split(
&self,
parts: usize,
axis: Option<usize>
) -> Result<Vec<Array<T>>, ArrayError>
fn array_split( &self, parts: usize, axis: Option<usize> ) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays
Arguments
parts
- indices defining how to split the arrayaxis
- the axis along which to split. optional, defaults to 0
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 7);
let split = arr.array_split(3, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4, 5).unwrap(), array_flat!(i32, 6, 7).unwrap()], split);
let arr = array_arange!(i32, 0, 8);
let split = arr.array_split(4, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4).unwrap(), array_flat!(i32, 5, 6).unwrap(), array_flat!(i32, 7, 8).unwrap()], split);
sourcefn split(
&self,
parts: usize,
axis: Option<usize>
) -> Result<Vec<Array<T>>, ArrayError>
fn split( &self, parts: usize, axis: Option<usize> ) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays of equal size
Arguments
parts
- indices defining how to split the arrayaxis
- the axis along which to split. optional, defaults to 0
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 8);
let split = arr.split(3, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1, 2).unwrap(), array_flat!(i32, 3, 4, 5).unwrap(), array_flat!(i32, 6, 7, 8).unwrap()], split);
let arr = array_arange!(i32, 0, 7);
let split = arr.split(4, None).unwrap();
assert_eq!(vec![array_flat!(i32, 0, 1).unwrap(), array_flat!(i32, 2, 3).unwrap(), array_flat!(i32, 4, 5).unwrap(), array_flat!(i32, 6, 7).unwrap()], split);
sourcefn split_axis(&self, axis: usize) -> Result<Vec<Array<T>>, ArrayError>
fn split_axis(&self, axis: usize) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays of equal size by axis
Arguments
axis
- the axis along which to split
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 3).reshape(&[2, 2]);
let split = arr.split_axis(0).unwrap();
assert_eq!(vec![array!(i32, [[0, 1]]).unwrap(), array!(i32, [[2, 3]]).unwrap()], split);
let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]);
let split = arr.split_axis(1).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1]], [[4, 5]]]).unwrap(), array!(i32, [[[2, 3]], [[6, 7]]]).unwrap()], split);
sourcefn hsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
fn hsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays horizontally (column-wise)
Arguments
parts
- indices defining how to split the array
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.hsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1]], [[4, 5]]]).unwrap(), array!(i32, [[[2, 3]], [[6, 7]]]).unwrap()], split);
sourcefn vsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
fn vsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays vertically (row-wise)
Arguments
parts
- indices defining how to split the array
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.vsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0, 1], [2, 3]]]).unwrap(), array!(i32, [[[4, 5], [6, 7]]]).unwrap()], split);
sourcefn dsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
fn dsplit(&self, parts: usize) -> Result<Vec<Array<T>>, ArrayError>
Split an array into multiple sub-arrays along the 3rd axis (depth)
Arguments
parts
- indices defining how to split the array
Examples
use arr_rs::prelude::*;
let arr = array_arange!(i32, 0, 7).reshape(&[2, 2, 2]).unwrap();
let split = arr.dsplit(2).unwrap();
assert_eq!(vec![array!(i32, [[[0], [2]], [[4], [6]]]).unwrap(), array!(i32, [[[1], [3]], [[5], [7]]]).unwrap()], split);