numpy.ufunc#

classnumpy.ufunc[source]#

Functions that operate element by element on whole arrays.

To see the documentation for a specific ufunc, useinfo. Forexample,np.info(np.sin). Because ufuncs are written in C(for speed) and linked into Python with NumPy’s ufunc facility,Python’s help() function finds this page whenever help() is calledon a ufunc.

A detailed explanation of ufuncs can be found in the docs forUniversal functions (ufunc).

Calling ufuncs:op(*x[,out],where=True,**kwargs)

Applyop to the arguments*x elementwise, broadcasting the arguments.

The broadcasting rules are:

  • Dimensions of length 1 may be prepended to either array.

  • Arrays may be repeated along dimensions of length 1.

Parameters:
*xarray_like

Input arrays.

outndarray, None, …, or tuple of ndarray and None, optional

Location(s) into which the result(s) are stored.If not provided or None, new array(s) are created by the ufunc.If passed as a keyword argument, can be Ellipses (out=...) toensure an array is returned even if the result is 0-dimensional,or a tuple with length equal to the number of outputs (where Nonecan be used for allocation by the ufunc).

New in version 2.3:Support forout=... was added.

wherearray_like, optional

This condition is broadcast over the input. At locations where thecondition is True, theout array will be set to the ufunc result.Elsewhere, theout array will retain its original value.Note that if an uninitializedout array is created via the defaultout=None, locations within it where the condition is False willremain uninitialized.

**kwargs

For other keyword-only arguments, see theufunc docs.

Returns:
rndarray or tuple of ndarray

r will have the shape that the arrays inx broadcast to; ifout isprovided, it will be returned. If not,r will be allocated andmay contain uninitialized values. If the function has more than oneoutput, then the result will be a tuple of arrays.

Attributes:
identity

The identity value.

nargs

The number of arguments.

nin

The number of inputs.

nout

The number of outputs.

ntypes

The number of types.

signature

Definition of the core elements a generalized ufunc operates on.

types

Returns a list with types grouped input->output.

Methods

__call__(*args, **kwargs)

Call self as a function.

accumulate(array[, axis, dtype, out])

Accumulate the result of applying the operator to all elements.

at(a, indices[, b])

Performs unbuffered in place operation on operand 'a' for elements specified by 'indices'.

outer(A, B, /, **kwargs)

Apply the ufuncop to all pairs (a, b) with a inA and b inB.

reduce(array[, axis, dtype, out, keepdims, ...])

Reducesarray's dimension by one, by applying ufunc along one axis.

reduceat(array, indices[, axis, dtype, out])

Performs a (local) reduce with specified slices over a single axis.

resolve_dtypes(dtypes, *[, signature, ...])

Find the dtypes NumPy will use for the operation.

On this page