[−][src]Crate np
np
is an easy-to-use fundamental library for scientific computing with
Rust, highly inspired by NumPy.
Usage
Add this to your Cargo.toml
:
[dependencies]
np = "2018.3.2"
To get started using np
, read the quickstart tutorial below.
Quickstart Tutorial
Prerequisites
Before reading this quick tutorial you should know a bit of Rust. If you would like to refresh your memory, take a look at the Rust book.
The Basics
np's main data type is the homogeneous multidimensional vector. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers.
For example, the coordinates of a point in 3D space [1, 2, 1]
has
one dimension. That dimension has 3 elements in it, so we say
it has a length of 3. In the example pictured below,
the vector has 2 dimensions. The first dimension has a length of 2,
the second dimension has a length of 3.
[ [ 1., 0., 0.], [ 0., 1., 2.] ]
np uses Rust's vector standard data type extensively. We don't reinvent yet-another data type to keep things simple and easy to use. np added useful attributes for Rust's vector like the following:
- dim: the number of dimensions of the vector.
- shape: This is a list of integers indicating the
size of the vector in each dimension.
For a matrix with
n
rows andm
columns, shape will be[n,m]
. The length of the shape is therefore the number of dimensions,dim()
. - size: the total number of elements of the vector. This is equal to the product of the elements of shape.
An Example
// Create two-dimensional vector with shape [3, 3] // filled with zeros let matrix: Vec<Vec<i32>> = Vec::two_dim(3, 3).zeros(); assert_eq!(matrix.dim(), 2); assert_eq!(matrix.shape(), [3, 3]); assert_eq!(matrix.size(), 9);
Getting help
Feel free to start discussion at GitHub issues.
License
np
is licensed under the BSD 3-Clause license.
Traits
Dimension | Dimension of the vector |
FourDimensional | Four-dimensional vectors |
Full | Fillable vectors |
OneDimensional | One-dimensional vectors |
Shape | A list of integers indicating the size of the vector in each dimension |
Size | Total number of elements of the vector |
ThreeDimensional | Three-dimensional vectors |
TwoDimensional | Two-dimensional vectors |
Zero | A zero-able vectors |
Functions
zeros |