# Struct rusty_machine::linalg::Vector [−]

`pub struct Vector<T> { /* fields omitted */ }`

The Vector struct.

Can be instantiated with any type.

## Methods

### `impl<T> Vector<T>`

#### `fn new<U>(data: U) -> Vector<T> where U: Into<Vec<T>>`

Constructor for Vector struct.

Requires the vector data.

# Examples

```use rulinalg::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 mut_data(&mut self) -> &mut [T]`

Returns a mutable slice of the underlying data.

#### `fn into_vec(self) -> Vec<T>`

Consumes the Vector and returns the Vec of data.

#### `fn iter(&self) -> Iter<T>`

Returns an iterator over the Vector's data.

#### `fn iter_mut(&mut self) -> IterMut<T>`

Returns an iterator over mutable references to the Vector's data.

### `impl<T> Vector<T> where T: Copy`

#### `fn apply(self, f: &Fn(T)) -> Vector<T>`

Applies a function to each element in the vector.

# Examples

```use rulinalg::vector::Vector;
fn add_two(a: f64) -> f64 {
a + 2f64
}

let a = Vector::new(vec![0.;4]);

assert_eq!(b.into_vec(), vec![2.0; 4]);```

### `impl<T> Vector<T> where T: Copy + PartialOrd<T>`

#### `fn argmax(&self) -> (usize, T)`

Find the argmax of the Vector.

Returns the index of the largest value in the vector.

# Examples

```use rulinalg::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 rulinalg::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 rulinalg::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> Vector<T> where T: Clone + Zero`

#### `fn zeros(size: usize) -> Vector<T>`

Constructs Vector of all zeros.

Requires the size of the vector.

# Examples

```use rulinalg::vector::Vector;

let vec = Vector::<f64>::zeros(10);```

### `impl<T> Vector<T> where T: Clone + One`

#### `fn ones(size: usize) -> Vector<T>`

Constructs Vector of all ones.

Requires the size of the vector.

# Examples

```use rulinalg::vector::Vector;

let vec = Vector::<f64>::ones(10);```

### `impl<T> Vector<T> where T: Add<T, Output=T> + Mul<T, Output=T> + Zero + Copy`

#### `fn dot(&self, v: &Vector<T>) -> T`

Compute dot product with specified Vector.

# Examples

```use rulinalg::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> Vector<T> where T: Copy + Add<T, Output=T> + Zero`

#### `fn sum(&self) -> T`

The sum of the vector.

Returns the sum of all elements in the vector.

# Examples

```use rulinalg::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> Vector<T> where T: Copy + Mul<T, Output=T>`

#### `fn elemul(&self, v: &Vector<T>) -> Vector<T>`

The elementwise product of two vectors.

# Examples

```use rulinalg::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> Vector<T> where T: Copy + Div<T, Output=T>`

#### `fn elediv(&self, v: &Vector<T>) -> Vector<T>`

The elementwise division of two vectors.

# Examples

```use rulinalg::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> Vector<T> where T: Float + FromPrimitive`

#### `fn mean(&self) -> T`

The mean of the vector.

Returns the arithmetic mean of the vector.

# Examples

```use rulinalg::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 rulinalg::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> Metric<T> for Vector<T> where T: Float`

#### `fn norm(&self) -> T`

Compute euclidean norm for vector.

# Examples

```use rulinalg::vector::Vector;
use rulinalg::Metric;

let a = Vector::new(vec![3.0,4.0]);
let c = a.norm();

assert_eq!(c, 5.0);```

### `impl<T> AddAssign<T> for Vector<T> where T: Copy + Add<T, Output=T>`

Performs addition assignment between a vector and a scalar.

### `impl<'a, T> AddAssign<&'a T> for Vector<T> where T: Copy + Add<T, Output=T>`

Performs addition assignment between a vector and a scalar.

### `impl<T> AddAssign<Vector<T>> for Vector<T> where T: Copy + Add<T, Output=T>`

Performs elementwise addition assignment between two vectors.

### `impl<'a, T> AddAssign<&'a Vector<T>> for Vector<T> where T: Copy + Add<T, Output=T>`

Performs elementwise addition assignment between two vectors.

### `impl<T> DivAssign<T> for Vector<T> where T: Copy + Div<T, Output=T>`

Performs division assignment between a vector and a scalar.

### `impl<'a, T> DivAssign<&'a T> for Vector<T> where T: Copy + Div<T, Output=T>`

Performs division assignment between a vector and a scalar.

### `impl<T> Into<Vec<T>> for Vector<T>`

#### `fn into(self) -> Vec<T>`

Performs the conversion.

### `impl<T> MulAssign<T> for Vector<T> where T: Copy + Mul<T, Output=T>`

Performs multiplication assignment between a vector and a scalar.

### `impl<'a, T> MulAssign<&'a T> for Vector<T> where T: Copy + Mul<T, Output=T>`

Performs multiplication assignment between a vector and a scalar.

### `impl<T> Sub<T> for Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts scalar from vector.

### `impl<'a, T> Sub<T> for &'a Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts scalar from vector.

### `impl<'a, T> Sub<&'a T> for Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts scalar from vector.

### `impl<'a, 'b, T> Sub<&'b T> for &'a Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts scalar from vector.

### `impl<T> Sub<Vector<T>> for Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts vector from vector.

### `impl<'a, T> Sub<Vector<T>> for &'a Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts vector from vector.

### `impl<'a, T> Sub<&'a Vector<T>> for Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts vector from vector.

### `impl<'a, 'b, T> Sub<&'b Vector<T>> for &'a Vector<T> where T: Copy + Sub<T, Output=T>`

Subtracts vector from vector.

### `impl<T> Clone for Vector<T> where T: Clone`

#### `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> Hash for Vector<T> where T: Hash`

#### `fn hash<__HT>(&self, __arg_0: &mut __HT) where __HT: Hasher`

Feeds this value into the state given, updating the hasher as necessary.

#### `fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher`1.3.0

Feeds a slice of this type into the state provided.

### `impl<T> Mul<T> for Vector<T> where T: Copy + Mul<T, Output=T>`

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> Mul<T> for &'a Vector<T> where T: Copy + Mul<T, Output=T>`

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> Mul<&'a T> for Vector<T> where T: Copy + Mul<T, Output=T>`

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> Mul<&'b T> for &'a Vector<T> where T: Copy + Mul<T, Output=T>`

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

Indexes vector.

### `impl<T> Add<T> for Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<T> for &'a Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<&'a T> for Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<&'b T> for &'a Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<Vector<T>> for Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<Vector<T>> for &'a Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<&'a Vector<T>> for Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> Add<&'b Vector<T>> for &'a Vector<T> where T: Copy + Add<T, Output=T>`

#### `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> PartialEq<Vector<T>> for Vector<T> where T: PartialEq<T>`

#### `fn eq(&self, __arg_0: &Vector<T>) -> bool`

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, __arg_0: &Vector<T>) -> bool`

This method tests for `!=`.

### `impl<T> IndexMut<usize> for Vector<T>`

Indexes mutable vector.

### `impl<T> Debug for Vector<T> where T: Debug`

#### `fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>`

Formats the value using the given formatter.

### `impl<T> SubAssign<T> for Vector<T> where T: Copy + Sub<T, Output=T>`

Performs subtraction assignment between a vector and a scalar.

### `impl<'a, T> SubAssign<&'a T> for Vector<T> where T: Copy + Sub<T, Output=T>`

Performs subtraction assignment between a vector and a scalar.

### `impl<T> SubAssign<Vector<T>> for Vector<T> where T: Copy + Sub<T, Output=T>`

Performs elementwise subtraction assignment between two vectors.

### `impl<'a, T> SubAssign<&'a Vector<T>> for Vector<T> where T: Copy + Sub<T, Output=T>`

Performs elementwise subtraction assignment between two vectors.

### `impl<T> Display for Vector<T> where T: Display`

#### `fn fmt(&self, f: &mut Formatter) -> Result<(), Error>`

Displays the Vector.

### `impl<T> From<Vec<T>> for Vector<T>`

#### `fn from(vec: Vec<T>) -> Vector<T>`

Performs the conversion.

### `impl<'a, T> From<&'a [T]> for Vector<T> where T: Clone`

#### `fn from(slice: &'a [T]) -> Vector<T>`

Performs the conversion.

### `impl<T> Div<T> for Vector<T> where T: Copy + Div<T, Output=T> + PartialEq<T> + Zero`

Divides vector by scalar.

### `impl<'a, T> Div<T> for &'a Vector<T> where T: Copy + Div<T, Output=T> + PartialEq<T> + Zero`

Divides vector by scalar.

### `impl<'a, T> Div<&'a T> for Vector<T> where T: Copy + Div<T, Output=T> + PartialEq<T> + Zero`

Divides vector by scalar.

### `impl<'a, 'b, T> Div<&'b T> for &'a Vector<T> where T: Copy + Div<T, Output=T> + PartialEq<T> + Zero`

Divides vector by scalar.

### `impl<T> Neg for Vector<T> where T: Copy + Neg<Output=T>`

Gets negative of vector.

### `impl<'a, T> Neg for &'a Vector<T> where T: Copy + Neg<Output=T>`

Gets negative of vector.