Struct rusty_machine::linalg::vector::Vector
[−]
[src]
pub struct Vector<T> {
// some fields omitted
}The Vector struct.
Can be instantiated with any type.
Methods
impl<T> Vector<T>[src]
fn new(data: Vec<T>) -> Vector<T>
Constructor for Vector struct.
Requires the vector data.
Examples
use rusty_machine::linalg::vector::Vector; let vec = Vector::new(vec![1.0,2.0,3.0,4.0]);
fn size(&self) -> usize
Returns the size of the Vector.
fn data(&self) -> &Vec<T>
Returns a non-mutable reference to the underlying data.
fn into_vec(self) -> Vec<T>
Consumes the Vector and returns the Vec of data.
impl<T: Copy> Vector<T>[src]
fn apply(self, f: &Fn(T) -> T) -> Vector<T>
Applies a function to each element in the vector.
Examples
use rusty_machine::linalg::vector::Vector; fn add_two(a: f64) -> f64 { a + 2f64 } let a = Vector::new(vec![0.;4]); let b = a.apply(&add_two); assert_eq!(b.into_vec(), vec![2.0; 4]);
impl<T: Copy + PartialOrd> Vector<T>[src]
fn argmax(&self) -> (usize, T)
Find the argmax of the Vector.
Returns the index of the largest value in the vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,0.0,5.0]); let b = a.argmax(); assert_eq!(b.0, 3); assert_eq!(b.1, 5.0);
fn argmin(&self) -> (usize, T)
Find the argmin of the Vector.
Returns the index of the smallest value in the vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,0.0,5.0]); let b = a.argmin(); assert_eq!(b.0, 2); assert_eq!(b.1, 0.0);
fn select(&self, idxs: &[usize]) -> Vector<T>
Select elements from the Vector and form a new Vector from them.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,3.0,4.0,5.0]); let a_lower = a.select(&[2,3,4]); // Prints [3,4,5] println!("{:?}", a_lower.data());
impl<T: Zero + One + Copy> Vector<T>[src]
fn zeros(size: usize) -> Vector<T>
Constructs Vector of all zeros.
Requires the size of the vector.
Examples
use rusty_machine::linalg::vector::Vector; let vec = Vector::<f64>::zeros(10);
fn ones(size: usize) -> Vector<T>
Constructs Vector of all ones.
Requires the size of the vector.
Examples
use rusty_machine::linalg::vector::Vector; let vec = Vector::<f64>::ones(10);
impl<T: Copy + One + Zero + Mul<T, Output=T> + Add<T, Output=T>> Vector<T>[src]
fn dot(&self, v: &Vector<T>) -> T
Compute dot product with specified Vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,3.0,4.0]); let b = Vector::new(vec![2.0; 4]); let c = a.dot(&b); assert_eq!(c, 20.0);
impl<T: Copy + Zero + Add<T, Output=T>> Vector<T>[src]
fn sum(&self) -> T
The sum of the vector.
Returns the sum of all elements in the vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,3.0,4.0]); let c = a.sum(); assert_eq!(c, 10.0);
impl<T: Copy + Zero + Mul<T, Output=T>> Vector<T>[src]
fn elemul(&self, v: &Vector<T>) -> Vector<T>
The elementwise product of two vectors.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,3.0,4.0]); let b = Vector::new(vec![1.0,2.0,3.0,4.0]); let c = &a.elemul(&b); assert_eq!(*c.data(), vec![1.0, 4.0, 9.0, 16.0]);
impl<T: Copy + Zero + Div<T, Output=T>> Vector<T>[src]
fn elediv(&self, v: &Vector<T>) -> Vector<T>
The elementwise division of two vectors.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::new(vec![1.0,2.0,3.0,4.0]); let b = Vector::new(vec![1.0,2.0,3.0,4.0]); let c = &a.elediv(&b); assert_eq!(*c.data(), vec![1.0; 4]);
impl<T: Copy + Zero + Float + FromPrimitive> Vector<T>[src]
fn mean(&self) -> T
The mean of the vector.
Returns the arithmetic mean of the vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::<f32>::new(vec![1.0,2.0,3.0,4.0]); let c = a.mean(); assert_eq!(c, 2.5);
fn variance(&self) -> T
The variance of the vector.
Returns the unbiased sample variance of the vector.
Examples
use rusty_machine::linalg::vector::Vector; let a = Vector::<f32>::new(vec![1.0,2.0,3.0,4.0]); let c = a.variance(); assert_eq!(c, 5.0/3.0);
Trait Implementations
impl<T: Clone> Clone for Vector<T>[src]
fn clone(&self) -> Vector<T>
Clones the Vector.
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl<T: Copy + One + Zero + Mul<T, Output=T>> Mul<T> for Vector<T>[src]
Multiplies vector by scalar.
type Output = Vector<T>
The resulting type after applying the * operator
fn mul(self, f: T) -> Vector<T>
The method for the * operator
impl<'a, T: Copy + One + Zero + Mul<T, Output=T>> Mul<T> for &'a Vector<T>[src]
Multiplies vector by scalar.
type Output = Vector<T>
The resulting type after applying the * operator
fn mul(self, f: T) -> Vector<T>
The method for the * operator
impl<'a, T: Copy + One + Zero + Mul<T, Output=T>> Mul<&'a T> for Vector<T>[src]
Multiplies vector by scalar.
type Output = Vector<T>
The resulting type after applying the * operator
fn mul(self, f: &T) -> Vector<T>
The method for the * operator
impl<'a, 'b, T: Copy + One + Zero + Mul<T, Output=T>> Mul<&'b T> for &'a Vector<T>[src]
Multiplies vector by scalar.
type Output = Vector<T>
The resulting type after applying the * operator
fn mul(self, f: &T) -> Vector<T>
The method for the * operator
impl<T: Copy + One + Zero + PartialEq + Div<T, Output=T>> Div<T> for Vector<T>[src]
Divides vector by scalar.
type Output = Vector<T>
The resulting type after applying the / operator
fn div(self, f: T) -> Vector<T>
The method for the / operator
impl<'a, T: Copy + One + Zero + PartialEq + Div<T, Output=T>> Div<T> for &'a Vector<T>[src]
Divides vector by scalar.
type Output = Vector<T>
The resulting type after applying the / operator
fn div(self, f: T) -> Vector<T>
The method for the / operator
impl<'a, T: Copy + One + Zero + PartialEq + Div<T, Output=T>> Div<&'a T> for Vector<T>[src]
Divides vector by scalar.
type Output = Vector<T>
The resulting type after applying the / operator
fn div(self, f: &T) -> Vector<T>
The method for the / operator
impl<'a, 'b, T: Copy + One + Zero + PartialEq + Div<T, Output=T>> Div<&'b T> for &'a Vector<T>[src]
Divides vector by scalar.
type Output = Vector<T>
The resulting type after applying the / operator
fn div(self, f: &T) -> Vector<T>
The method for the / operator
impl<T: Copy + One + Zero + Add<T, Output=T>> Add<T> for Vector<T>[src]
Adds scalar to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, f: T) -> Vector<T>
The method for the + operator
impl<'a, T: Copy + One + Zero + Add<T, Output=T>> Add<T> for &'a Vector<T>[src]
Adds scalar to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, f: T) -> Vector<T>
The method for the + operator
impl<'a, T: Copy + One + Zero + Add<T, Output=T>> Add<&'a T> for Vector<T>[src]
Adds scalar to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, f: &T) -> Vector<T>
The method for the + operator
impl<'a, 'b, T: Copy + One + Zero + Add<T, Output=T>> Add<&'b T> for &'a Vector<T>[src]
Adds scalar to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, f: &T) -> Vector<T>
The method for the + operator
impl<T: Copy + One + Zero + Add<T, Output=T>> Add<Vector<T>> for Vector<T>[src]
Adds vector to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, v: Vector<T>) -> Vector<T>
The method for the + operator
impl<'a, T: Copy + One + Zero + Add<T, Output=T>> Add<Vector<T>> for &'a Vector<T>[src]
Adds vector to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, v: Vector<T>) -> Vector<T>
The method for the + operator
impl<'a, T: Copy + One + Zero + Add<T, Output=T>> Add<&'a Vector<T>> for Vector<T>[src]
Adds vector to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, v: &Vector<T>) -> Vector<T>
The method for the + operator
impl<'a, 'b, T: Copy + One + Zero + Add<T, Output=T>> Add<&'b Vector<T>> for &'a Vector<T>[src]
Adds vector to vector.
type Output = Vector<T>
The resulting type after applying the + operator
fn add(self, v: &Vector<T>) -> Vector<T>
The method for the + operator
impl<T: Copy + One + Zero + Sub<T, Output=T>> Sub<T> for Vector<T>[src]
Subtracts scalar from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, f: T) -> Vector<T>
The method for the - operator
impl<'a, T: Copy + One + Zero + Sub<T, Output=T>> Sub<T> for &'a Vector<T>[src]
Subtracts scalar from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, f: T) -> Vector<T>
The method for the - operator
impl<'a, T: Copy + One + Zero + Sub<T, Output=T>> Sub<&'a T> for Vector<T>[src]
Subtracts scalar from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, f: &T) -> Vector<T>
The method for the - operator
impl<'a, 'b, T: Copy + One + Zero + Sub<T, Output=T>> Sub<&'b T> for &'a Vector<T>[src]
Subtracts scalar from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, f: &T) -> Vector<T>
The method for the - operator
impl<T: Copy + One + Zero + Sub<T, Output=T>> Sub<Vector<T>> for Vector<T>[src]
Subtracts vector from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, v: Vector<T>) -> Vector<T>
The method for the - operator
impl<'a, T: Copy + One + Zero + Sub<T, Output=T>> Sub<Vector<T>> for &'a Vector<T>[src]
Subtracts vector from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, v: Vector<T>) -> Vector<T>
The method for the - operator
impl<'a, T: Copy + One + Zero + Sub<T, Output=T>> Sub<&'a Vector<T>> for Vector<T>[src]
Subtracts vector from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, v: &Vector<T>) -> Vector<T>
The method for the - operator
impl<'a, 'b, T: Copy + One + Zero + Sub<T, Output=T>> Sub<&'b Vector<T>> for &'a Vector<T>[src]
Subtracts vector from vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn sub(self, v: &Vector<T>) -> Vector<T>
The method for the - operator
impl<T: Neg<Output=T> + Copy> Neg for Vector<T>[src]
Gets negative of vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn neg(self) -> Vector<T>
The method for the unary - operator
impl<'a, T: Neg<Output=T> + Copy> Neg for &'a Vector<T>[src]
Gets negative of vector.
type Output = Vector<T>
The resulting type after applying the - operator
fn neg(self) -> Vector<T>
The method for the unary - operator
impl<T> Index<usize> for Vector<T>[src]
Indexes vector.
type Output = T
The returned type after indexing
fn index(&self, idx: usize) -> &T
The method for the indexing (Foo[Bar]) operation