pub struct Array<T: Copy> {
pub data: Rc<RefCell<Vec<T>>>,
pub shape: Shape,
}
Expand description
Array structure
Fields§
§data: Rc<RefCell<Vec<T>>>
§shape: Shape
Implementations§
Source§impl<T: Copy> Array<T>
impl<T: Copy> Array<T>
Sourcepub fn new_bounded(
data: Vec<T>,
shape: Vec<i32>,
start: usize,
end: usize,
) -> Array<T>
pub fn new_bounded( data: Vec<T>, shape: Vec<i32>, start: usize, end: usize, ) -> Array<T>
Creates new bounded array
§Arguments
data
- array elementsshape
- vector representing array shapestart
- start offset of array dataend
- end offset of array data
Sourcepub fn set(&self, indices: Vec<usize>, value: T)
pub fn set(&self, indices: Vec<usize>, value: T)
Set values on given indices to given value
§Arguments
indices
- vector of indicesvalue
- value to fill it with
§Examples
#[macro_use] extern crate numas;
use numas::array::Array;
let f_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
// first row
f_array.set(s![0], -1);
assert_eq!(f_array.collect(), vec![-1,-1,-1,4,5,6,7,8,9]);
let s_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
// fist two rows
s_array.set(s![0 => 2], -1);
assert_eq!(s_array.collect(), vec![-1,-1,-1,-1,-1,-1,7,8,9]);
let t_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
// second row, second column
t_array.set(s![1; 1], -1);
assert_eq!(t_array.collect(), vec![1,2,3,4,-1,6,7,8,9]);
let x_array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
// last row, two last columns
x_array.set(s![2; 1 => 3], -1);
assert_eq!(x_array.collect(), vec![1,2,3,4,5,6,7,-1,-1]);
Sourcepub fn get(&self, indices: Vec<usize>) -> Array<T>
pub fn get(&self, indices: Vec<usize>) -> Array<T>
Return new Array from given indices
§Arguments
indices
- vector of indices
§Examples
#[macro_use] extern crate numas;
use numas::array::Array;
let array = Array::new(vec![1,2,3,4,5,6,7,8,9], vec![3,3]);
// first row
assert_eq!(array.get(s![0]).collect(), vec![1,2,3]);
// fist two rows
assert_eq!(array.get(s![0 => 2]).collect(), vec![1,2,3,4,5,6]);
// second row, second column
assert_eq!(array.get(s![1; 1]).collect(), vec![5]);
// last row, two last columns
assert_eq!(array.get(s![2; 1 => 3]).collect(), vec![8,9]);
Source§impl<T> Array<T>where
T: Copy + PartialOrd,
impl<T> Array<T>where
T: Copy + PartialOrd,
Sourcepub fn lt(&self, other: &Array<T>) -> Array<u8>
pub fn lt(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of lesser than element wise
§Arguments
other
- Array to compare with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 3], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let less = first.lt(&second);
assert_eq!(less.collect(), vec![0, 0, 0, 1]);
Sourcepub fn le(&self, other: &Array<T>) -> Array<u8>
pub fn le(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of lesser equal element wise
§Arguments
other
- Array to compare with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 3], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let less_equal = first.le(&second);
assert_eq!(less_equal.collect(), vec![1, 0, 1, 1]);
Sourcepub fn gt(&self, other: &Array<T>) -> Array<u8>
pub fn gt(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of greater than element wise
§Arguments
other
- Array to compare with with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 3], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let greater = first.gt(&second);
assert_eq!(greater.collect(), vec![0, 1, 0, 0]);
Sourcepub fn ge(&self, other: &Array<T>) -> Array<u8>
pub fn ge(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of greater equal element wise
§Arguments
other
- Array to compare with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 3], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let greater_equal = first.ge(&second);
assert_eq!(greater_equal.collect(), vec![1, 1, 1, 0]);
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn eq(&self, other: &Array<T>) -> Array<u8>
pub fn eq(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of equality element wise
§Arguments
other
- Array to comapre with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 4], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let equality = first.eq(&second);
assert_eq!(equality.collect(), vec![1, 0, 1, 1]);
Sourcepub fn neq(&self, other: &Array<T>) -> Array<u8>
pub fn neq(&self, other: &Array<T>) -> Array<u8>
Returns array of 1s and 0s representing truth value of not equality element wise
§Arguments
other
- Array to compare with
§Examples
use numas::array::Array;;
let first = Array::new(vec![1, 2, 3, 4], vec![4]);
let second = Array::new(vec![1, 0, 3, 4], vec![4]);
let not_equality = first.neq(&second);
assert_eq!(not_equality.collect(), vec![0, 1, 0, 0]);
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn sinh(&self) -> Array<f64>
pub fn sinh(&self) -> Array<f64>
Applies hyperbolic sine on elements from given array and creates new array
Sourcepub fn cosh(&self) -> Array<f64>
pub fn cosh(&self) -> Array<f64>
Applies hyperbolic cosine on elements from given array and creates new array
Sourcepub fn tanh(&self) -> Array<f64>
pub fn tanh(&self) -> Array<f64>
Applies hyperbolic tangent on elements from given array and creates new array
Sourcepub fn arcsinh(&self) -> Array<f64>
pub fn arcsinh(&self) -> Array<f64>
Applies inverse hyperbolic sine on elements from given array and creates new array
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn sin(&self) -> Array<f64>
pub fn sin(&self) -> Array<f64>
Applies sine on elements from given array and creates new array
Sourcepub fn cos(&self) -> Array<f64>
pub fn cos(&self) -> Array<f64>
Applies cosine on elements from given array and creates new array
Sourcepub fn tan(&self) -> Array<f64>
pub fn tan(&self) -> Array<f64>
Applies tangent on elements from given array and creates new array
Sourcepub fn arcsin(&self) -> Array<f64>
pub fn arcsin(&self) -> Array<f64>
Applies inverse sine on elements from given array and creates new array
Sourcepub fn arccos(&self) -> Array<f64>
pub fn arccos(&self) -> Array<f64>
Applies inverse cosine on elements from given array and creates new array
Sourcepub fn arctan(&self) -> Array<f64>
pub fn arctan(&self) -> Array<f64>
Applies inverse tangent on elements from given array and creates new array
Sourcepub fn degrees(&self) -> Array<f64>
pub fn degrees(&self) -> Array<f64>
Converts elements from given array to degrees and creates new array
Sourcepub fn radians(&self) -> Array<f64>
pub fn radians(&self) -> Array<f64>
Converts elements from given array to radians and creates new array
Source§impl<T> Array<T>
impl<T> Array<T>
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn sqrt(&self) -> Array<f64>
pub fn sqrt(&self) -> Array<f64>
Applies square root on elements from given array and creates new array
§Examples
use numas::array::Array;
let array = Array::new(vec![4, 9, 16, 25], vec![4]);
let sqrt_array = array.sqrt();
let data = sqrt_array.collect();
assert_eq!(data, vec![2.0, 3.0, 4.0, 5.0]);
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn round(&self) -> Array<f64>
pub fn round(&self) -> Array<f64>
Applies rounding on elements from given array and creates new array
§Examples
use numas::array::Array;
let array = Array::new(vec![1.4, 1.5, 2.1, 2.6], vec![4]);
let rounded = array.round();
let data = rounded.collect();
assert_eq!(data, vec![1.0, 2.0, 2.0, 3.0]);
Sourcepub fn ceil(&self) -> Array<f64>
pub fn ceil(&self) -> Array<f64>
Applies round ceil on elements from given array and creates new array
§Examples
use numas::array::Array;
let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
let rounded = array.ceil();
let data = rounded.collect();
assert_eq!(data, vec![2.0, -1.0, 3.0, 3.0]);
Sourcepub fn floor(&self) -> Array<f64>
pub fn floor(&self) -> Array<f64>
Applies round floor on elements from given array and creates new array
§Examples
use numas::array::Array;
let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
let rounded = array.floor();
let data = rounded.collect();
assert_eq!(data, vec![1.0, -2.0, 2.0, 2.0]);
Sourcepub fn trunc(&self) -> Array<f64>
pub fn trunc(&self) -> Array<f64>
Applies truncating on elements from given array and creates new array
§Examples
use numas::array::Array;
let array = Array::new(vec![1.4, -1.5, 2.1, 2.6], vec![4]);
let rounded = array.round();
let data = rounded.collect();
assert_eq!(data, vec![1.0, -2.0, 2.0, 3.0]);
Source§impl<T> Array<T>
impl<T> Array<T>
Sourcepub fn log(&self, base: f64) -> Array<f64>
pub fn log(&self, base: f64) -> Array<f64>
Applies logarithm with given base on elements from given array and creates new array
Sourcepub fn log2(&self) -> Array<f64>
pub fn log2(&self) -> Array<f64>
Applies logarithm with base 2 on elements from given array and creates new array
Trait Implementations§
Source§impl<T> AddAssign for &Array<T>
impl<T> AddAssign for &Array<T>
Source§fn add_assign(&mut self, other: &Array<T>)
fn add_assign(&mut self, other: &Array<T>)
+=
operation. Read moreSource§impl<T> DivAssign for &Array<T>
impl<T> DivAssign for &Array<T>
Source§fn div_assign(&mut self, other: &Array<T>)
fn div_assign(&mut self, other: &Array<T>)
/=
operation. Read moreSource§impl<T> MulAssign for &Array<T>
impl<T> MulAssign for &Array<T>
Source§fn mul_assign(&mut self, other: &Array<T>)
fn mul_assign(&mut self, other: &Array<T>)
*=
operation. Read more