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,.npzand CSV files, likenp.save,np.load,np.savez,np.savetxtandnp.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 NumPycomplex128(complex64forf32).
Enums§
- Bins
- The
binsargument ofhistogram: a number of equal-width bins or explicit bin edges. - Convolve
Mode - Output size of
convolveandcorrelate, like NumPy’smode="full" | "same" | "valid". - Error
- A data error, like NumPy’s I/O, parsing, or linear algebra exceptions.
- Slice
Arg - An index or slice, like a NumPy index tuple entry.
- Spacing
- Sample spacing for
gradient_axisandtrapezoid: 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.
- Into
Array - 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:0forx >= 0andpiforx < 0(angle(-0.0)ispi, 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 ofmpoints. - bincount
- Count occurrences of each non-negative integer, like
np.bincount(x, weights, minlength). - blackman
- Equivalent of
np.blackman(M): the Blackman window ofmpoints. - 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 ofawith the sign ofb. - corrcoef
- Pearson correlation matrix of the rows of
x, likenp.corrcoef(x). - correlate
- Cross-correlation of two 1-d arrays, like
np.correlate(a, v, mode). - cov
- Covariance matrix of the rows of
m, likenp.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 alongaxis, likenp.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 infloat64. - floor_
divide - Equivalent of
np.floor_divide(a, b)(a // b): the floor of the quotient. - fmod
- Equivalent of
np.fmod(a, b): Cfmod, 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)forint64arrays: the greatest common divisor, never negative. - gradient
- Numerical gradient along every axis with constant spacing
dx, likenp.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 ofmpoints. - hanning
- Equivalent of
np.hanning(M): the Hann window ofmpoints (m = 0is empty,m = 1is[1]). - heaviside
- Equivalent of
np.heaviside(x, h0):0forx < 0,h0at0,1forx > 0, NaN for NaN. - histogram
- Histogram of the flattened data, like
np.histogram(a, bins, range, density, weights). - histogram_
bin_ edges - Bin edges that
histogramwould use, likenp.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 ofmpoints with shape parameterbeta. - kron
- Kronecker product, like
np.kron(a, b). - lcm
- Equivalent of
np.lcm(a, b)forint64arrays: the least common multiple, never negative (wraps on overflow like NumPy). - ldexp
- Equivalent of
np.ldexp(a, e):a * 2**ewith 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 afteratowardsb. - 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), likenp.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
athat are not inb, likenp.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, likenp.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.