Some useful extensions for NumPy
Project description
npx
NumPy and SciPy are large libraries used everywhere in scientific computing. That's why breaking backwards-compatibility comes as a significant cost and is almost always avoided, even if the API of some methods is arguably lacking. This package provides drop-in wrappers "fixing" those.
If you have a fix for a NumPy method that can't go upstream for some reason, feel free to PR here.
-
npx.dot(a, b)
Forms the dot product between the last axis of
a
and the first axis ofb
.(Not the second-last axis of
b
asnumpy.dot(a, b)
.) -
npx.solve(A, b)
Solves a linear equation system with a matrix of shape
(n, n)
and an array of shape(n, ...)
. The output has the same shape as the second argument. -
npx.sum_at(a, idx, minlength: int = 0) npx.add_at(out, idx, a)
Returns an array with entries of
a
summed up at indicesidx
with a minumum length ofminlength
.idx
can have any shape as long as it's matchinga
. The output shape is(minlength,...)
.The numpy equivalent
numpy.add.at
is much slower:(See also this numpy bug.)
-
npx.unique_rows(a, return_inverse=False, return_counts=False)
Returns the unique rows of the integer array
a
. The numpy alternativenp.unique(a, axis=0)
is slow. -
sol, info = npx.cg(A, b, tol=1.0e-10) sol, info = npx.minres(A, b, tol=1.0e-10) sol, info = npx.gmres(A, b, tol=1.0e-10)
sol
is the solution of the linear systemA @ x = b
(orNone
if no convergence), andinfo
contains some useful data, e.g.,info.resnorms
. The methods are wrappers around SciPy's iterative solvers.
License
npx is published under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.