bundles / numpy 2.4.3 / numpy / frompyfunc
built-in
numpy:frompyfunc
Summary
Takes an arbitrary Python function and returns a NumPy ufunc.
Extended Summary
Can be used, for example, to add broadcasting to a built-in Python function (see Examples section).
Parameters
func: Python function objectAn arbitrary Python function.
nin: intThe number of input arguments.
nout: intThe number of objects returned by func.
identity: object, optionalThe value to use for the
~numpy.ufunc.identityattribute of the resulting object. If specified, this is equivalent to setting the underlying Cidentityfield toPyUFunc_IdentityValue. If omitted, the identity is set toPyUFunc_None. Note that this is _not_ equivalent to setting the identity toNone, which implies the operation is reorderable.
Returns
out: ufuncReturns a NumPy universal function (
ufunc) object.
Notes
The returned ufunc always returns PyObject arrays.
Examples
Use frompyfunc to add broadcasting to the Python function ``oct``:import numpy as np oct_array = np.frompyfunc(oct, 1, 1) oct_array(np.array((10, 30, 100))) np.array((oct(10), oct(30), oct(100))) # for comparison✓
See also
- vectorize
Evaluates pyfunc over input arrays using broadcasting rules of numpy.
Aliases
-
numpy.frompyfunc