Skip to main content

Crate rustnum

Crate rustnum 

Source
Expand description

NumPy-style arrays for Rust, like numpy.

use rustnum as np;
let a=np::array![[1,2],[3,4]];
assert_eq!(a.sum(),10);

Integer arithmetic retains the array dtype; addition, subtraction, multiplication, and integer powers wrap on overflow. Generic callbacks are serial so they can capture non-Sync state. Built-in element-wise operations and large contiguous reductions use Rayon when enabled. Empty/all-NaN statistics return NaN without Python’s runtime warning mechanism. Axis parameters precede ddof.

use rustnum as np;
let a:np::Array<f64>=np::array![1.,2.];
assert_eq!((&a*2.).to_vec(),[2.,4.]);
assert_eq!((2.*&a).to_vec(),[2.,4.]);
assert_eq!(format!("{}",a),"[1. 2.]");
assert_eq!(format!("{:?}",a),"array([1., 2.], dtype=float64)");

Modules§

fft
Discrete Fourier transforms, like np.fft.
io
I/O for arrays: .npy, .npz and CSV files, like np.save, np.load, np.savez, np.savetxt and np.loadtxt.
linalg
Linear algebra, like numpy.linalg.
memory
Buffer-cache controls, analogous to NumPy’s internal allocation cache.
poly
Polynomials with coefficients stored highest power first, like NumPy’s legacy np.poly* functions (np.polyval, np.polyfit, np.roots, …).
random
Random number generation, like np.random.

Macros§

array
Creates array literals, like np.array, supporting one through three dimensions.
s
Builds a slice tuple, like NumPy’s a[start:stop:step, …] syntax.

Structs§

Array
A homogeneous array, like np.ndarray, with copy-on-write value semantics.
Complex
A complex number re + im*j, like NumPy complex128 (complex64 for f32).

Enums§

Bins
The bins argument of histogram: a number of equal-width bins or explicit bin edges.
ConvolveMode
Output size of convolve and correlate, like NumPy’s mode="full" | "same" | "valid".
Error
A data error, like NumPy’s I/O, parsing, or linear algebra exceptions.
SliceArg
An index or slice, like a NumPy index tuple entry.
Spacing
Sample spacing for gradient_axis and trapezoid: a constant step or the sample coordinates.

Constants§

NEW_AXIS
Inserts a singleton axis, like np.newaxis.

Traits§

Element
A value which can be stored in an array, like a NumPy dtype.
Float
A floating point array element, like NumPy floating dtypes.
IntoArray
Converts an array-like value into an array, like NumPy asarray.
Num
A numeric array element, like NumPy numeric dtypes.

Functions§

angle
Equivalent of np.angle(a) for real input: 0 for x >= 0 and pi for x < 0 (angle(-0.0) is pi, NaN stays NaN).
angle_deg
Equivalent of np.angle(a, deg=True) for real input: the angle in degrees.
arange
Creates evenly stepped values, like np.arange. Implements np.arange with array value semantics.
arctan2
Implements np.arctan2 with array value semantics.
argwhere
Implements np.argwhere with array value semantics.
array_split
Implements np.array_split with array value semantics.
average
Weighted mean of all elements, like np.average(a, weights=weights).
average_axis
Weighted mean along an axis, like np.average(a, axis=axis, weights=weights).
bartlett
Equivalent of np.bartlett(M): the Bartlett (triangular) window of m points.
bincount
Count occurrences of each non-negative integer, like np.bincount(x, weights, minlength).
blackman
Equivalent of np.blackman(M): the Blackman window of m points.
broadcast_arrays
Broadcasts two arrays, like np.broadcast_arrays. Implements np.broadcast_arrays with array value semantics.
broadcast_shapes
Computes the common shape, like NumPy broadcasting. Implements np.broadcast_shapes with array value semantics.
concatenate
Implements np.concatenate with array value semantics.
convolve
Discrete linear convolution of two 1-d arrays, like np.convolve(a, v, mode).
copysign
Equivalent of np.copysign(a, b): the magnitude of a with the sign of b.
corrcoef
Pearson correlation matrix of the rows of x, like np.corrcoef(x).
correlate
Cross-correlation of two 1-d arrays, like np.correlate(a, v, mode).
cov
Covariance matrix of the rows of m, like np.cov(m, bias=bias, ddof=ddof).
cross
Cross product of 3-vectors (or 2-vectors) along the last axis, like np.cross(a, b).
diag
Implements np.diag with array value semantics.
diff
The n-th discrete difference along axis, like np.diff(a, n, axis).
digitize
Index of the bin each value falls into, like np.digitize(x, bins, right).
divmod
Equivalent of np.divmod(a, b): (floor_divide(a, b), remainder(a, b)) in one pass.
ediff1d
Equivalent of np.ediff1d(a): differences between consecutive elements of the flattened array.
ediff1d_with
Equivalent of np.ediff1d(a, to_end=to_end, to_begin=to_begin).
einsum
Einstein summation, like np.einsum(subscripts, *operands).
eye
Implements np.eye with array value semantics.
float_power
Equivalent of np.float_power(a, b): a power always computed in float64.
floor_divide
Equivalent of np.floor_divide(a, b) (a // b): the floor of the quotient.
fmod
Equivalent of np.fmod(a, b): C fmod, the remainder has the sign of the dividend.
full
Creates a filled array, like np.full. Implements np.full with array value semantics.
full_like
Implements np.full_like with array value semantics.
gcd
Equivalent of np.gcd(a, b) for int64 arrays: the greatest common divisor, never negative.
gradient
Numerical gradient along every axis with constant spacing dx, like np.gradient(f, dx).
gradient_axis
Gradient along one axis, like np.gradient(f, spacing, axis=axis, edge_order=edge_order).
hamming
Equivalent of np.hamming(M): the Hamming window of m points.
hanning
Equivalent of np.hanning(M): the Hann window of m points (m = 0 is empty, m = 1 is [1]).
heaviside
Equivalent of np.heaviside(x, h0): 0 for x < 0, h0 at 0, 1 for x > 0, NaN for NaN.
histogram
Histogram of the flattened data, like np.histogram(a, bins, range, density, weights).
histogram_bin_edges
Bin edges that histogram would use, like np.histogram_bin_edges(a, bins, range).
hstack
Implements np.hstack with array value semantics.
hypot
Implements np.hypot with array value semantics.
identity
Implements np.identity with array value semantics.
interp
One-dimensional piecewise-linear interpolation, like np.interp(x, xp, fp, left, right).
intersect1d
Sorted values present in both arrays, like np.intersect1d(a, b).
isclose
Implements np.isclose with array value semantics.
isin
Membership test, like np.isin(element, test_elements).
kaiser
Equivalent of np.kaiser(M, beta): the Kaiser window of m points with shape parameter beta.
kron
Kronecker product, like np.kron(a, b).
lcm
Equivalent of np.lcm(a, b) for int64 arrays: the least common multiple, never negative (wraps on overflow like NumPy).
ldexp
Equivalent of np.ldexp(a, e): a * 2**e with an integer exponent array.
linspace
Creates evenly spaced values, like np.linspace. Implements np.linspace with array value semantics.
logaddexp
Equivalent of np.logaddexp(a, b): log(exp(a) + exp(b)) without overflow.
logaddexp2
Equivalent of np.logaddexp2(a, b): log2(2**a + 2**b) without overflow.
logical_and
Implements np.logical_and with array value semantics.
logical_not
Implements np.logical_not with array value semantics.
logical_or
Implements np.logical_or with array value semantics.
logical_xor
Implements np.logical_xor with array value semantics.
logspace
Implements np.logspace with array value semantics.
maximum
Implements np.maximum with array value semantics.
meshgrid
Implements np.meshgrid with array value semantics.
minimum
Implements np.minimum with array value semantics.
nanquantile
Quantile ignoring NaNs, like np.nanquantile(a, q).
nanquantile_axis
NaN-ignoring quantile along an axis, like np.nanquantile(a, q, axis=axis).
nextafter
Equivalent of np.nextafter(a, b): the next representable float after a towards b.
nonzero
Implements np.nonzero with array value semantics.
ones
Creates ones, like np.ones. Implements np.ones with array value semantics.
ones_like
Implements np.ones_like with array value semantics.
pad
Implements np.pad with array value semantics.
power
Implements np.power with array value semantics.
quantile
The q-th quantile of all elements (linear interpolation), like np.quantile(a, q).
quantile_axis
Quantile along an axis, like np.quantile(a, q, axis=axis).
remainder
Equivalent of np.remainder(a, b) / np.mod(a, b): the remainder has the sign of the divisor (Python %).
searchsorted
Implements np.searchsorted with array value semantics.
setdiff1d
Sorted distinct values of a that are not in b, like np.setdiff1d(a, b).
setxor1d
Sorted values that are in exactly one of the arrays, like np.setxor1d(a, b).
split
Implements np.split with array value semantics.
stack
Implements np.stack with array value semantics.
trapezoid
Integrate with the trapezoidal rule along axis, like np.trapezoid(y, x_or_dx, axis=axis).
tri
Implements np.tri with array value semantics.
tril
Implements np.tril with array value semantics.
triu
Implements np.triu with array value semantics.
union1d
Sorted distinct values present in either array, like np.union1d(a, b).
unique
Implements np.unique with array value semantics.
unique_counts
Implements np.unique(return_counts=True) with array value semantics.
vstack
Implements np.vstack with array value semantics.
where_
Implements np.where with array value semantics.
zeros
Creates zeros, like np.zeros. Implements np.zeros with array value semantics.
zeros_like
Implements np.zeros_like with array value semantics.

Type Aliases§

Result
A fallible result, like a NumPy call that may raise a data exception.