FrankenNumPy

Docs/Numerics

Array Manipulation Toolkit

On this page 4 sections

Construction

Function What it does
zeros(shape) Array filled with 0.0
ones(shape) Array filled with 1.0
full(shape, val) Array filled with arbitrary value
empty(shape) Rust UFuncArray::empty allocates and zero-fills (it is zeros; safe Rust has no uninitialized allocation). Python fnp_python.empty calls numpy.empty, whose contents are uninitialized as in NumPy
eye(n, m, k) Identity-like matrix with diagonal offset k
identity(n) Square identity matrix (delegates to eye)
diag(v, k) 1-D input: construct diagonal matrix. 2-D input: extract diagonal.
arange(start, stop, step) Evenly spaced values within an interval
linspace(start, stop, num) num evenly spaced values including endpoints
logspace(start, stop, num) Values evenly spaced on a log scale
geomspace(start, stop, num) Values evenly spaced on a geometric scale
meshgrid(x, y, ...) Coordinate matrices with xy/ij, sparse, copy parity
mgrid[...] Dense grid object with NumPy slice semantics
ogrid[...] Open grid object with sparse tuple semantics
fromfunction(shape, f) Apply closure f(&[usize]) -> f64 to each multi-index

Joining and Splitting

Function Axis behavior
concatenate(arrays, axis) Join along existing axis
stack(arrays, axis) Join along new axis (all arrays must have identical shape)
vstack / row_stack Stack vertically (axis 0). Promotes 1-D to (1, N).
hstack Stack horizontally. For 1-D: axis 0. For N-D: axis 1.
dstack Stack along axis 2. Promotes to at least 3-D first.
column_stack Stack 1-D arrays as columns of a 2-D array
r_[...] Row-wise concatenation object with slice expansion and NumPy directive fallback
c_[...] Column-wise concatenation object with 1-D-to-column promotion and NumPy directive fallback
block(grid) Assemble from nested grid (concatenates within rows, then stacks)
split(ary, n, axis) Split into n equal sub-arrays
array_split(ary, n, axis) Split allowing unequal sub-arrays

Rearranging

Function What it does
transpose(axes) Permute dimensions
moveaxis(src, dst) Move one axis to a new position
rollaxis(axis, start) Roll axis backward until before start
swapaxes(a1, a2) Swap two axes via permutation
expand_dims(axis) Insert size-1 dimension
squeeze(axis) Remove size-1 dimensions
flip(axis) Reverse elements along axis
fliplr / flipud Left-right / up-down reversal
rot90(k) Rotate by k·90° on first two axes
roll(shift, axis) Circular shift with wrapping
tile(reps) Repeat array along each axis per reps
repeat(n, axis) Repeat each element n times
resize(new_shape) Resize with cyclic repetition if new shape is larger

Advanced Indexing

Function What it does
take(indices, axis) Select elements by integer indices
put(indices, values) Replace flat-indexed elements (cyclic values)
compress(condition, axis) Select elements where boolean condition is true
extract(condition, arr) Flat extraction by boolean mask
place(mask, vals) In-place replacement where mask is true
putmask(mask, values) In-place masked scatter with cyclic value repetition
indices(dimensions, dtype) Dense grid of coordinate indices
diag(v, k) Construct or extract a diagonal with offset k
diagflat(v, k) Flatten input and place values on a diagonal matrix
diagonal(a, offset, axis1, axis2) Extract a diagonal across arbitrary axes
fill_diagonal(a, val, wrap) In-place diagonal fill with NumPy wrap semantics
ix_(*args) Open mesh of broadcastable index vectors
diag_indices(n, ndim) Tuple of diagonal index arrays
tril_indices(n, k, m) Lower-triangle row/column index tuple
triu_indices(n, k, m) Upper-triangle row/column index tuple
select(condlist, choicelist, default) Choose from multiple arrays by first-matching condition
piecewise(condlist, funclist) Piecewise constant function via condition list
take_along_axis(indices, axis) Gather values along axis by index array
put_along_axis(indices, values, axis) Scatter values along axis by index array
ravel_multi_index(coords, shape) Convert N-D coordinates to flat indices
unravel_index(indices, shape) Convert flat indices to N-D coordinates

This section in the README on GitHub