numpy.frompyfunc#

numpy.frompyfunc(func,/,nin,nout,*[,identity])#

Takes an arbitrary Python function and returns a NumPy ufunc.

Can be used, for example, to add broadcasting to a built-in Pythonfunction (see Examples section).

Parameters:
funcPython function object

An arbitrary Python function.

ninint

The number of input arguments.

noutint

The number of objects returned byfunc.

identityobject, optional

The value to use for theidentity attribute of the resultingobject. If specified, this is equivalent to setting the underlyingCidentity field toPyUFunc_IdentityValue.If omitted, the identity is set toPyUFunc_None. Note that this is_not_ equivalent to setting the identity toNone, which implies theoperation is reorderable.

Returns:
outufunc

Returns a NumPy universal function (ufunc) object.

See also

vectorize

Evaluates pyfunc over input arrays using broadcasting rules of numpy.

Notes

The returned ufunc always returns PyObject arrays.

Examples

Use frompyfunc to add broadcasting to the Python functionoct:

>>>importnumpyasnp>>>oct_array=np.frompyfunc(oct,1,1)>>>oct_array(np.array((10,30,100)))array(['0o12', '0o36', '0o144'], dtype=object)>>>np.array((oct(10),oct(30),oct(100)))# for comparisonarray(['0o12', '0o36', '0o144'], dtype='<U5')
On this page