mygrad.reciprocal#

class mygrad.reciprocal(x: ArrayLike, out: Tensor | ndarray | None = None, *, where: Mask = True, dtype: DTypeLikeReals = None, constant: bool | None = None)#

Return the reciprocal of the argument element-wise.

This docstring was adapted from that of numpy.reciprocal [1]

Parameters:
xArrayLike

Input array.

constantOptional[bool]

If True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e. constant.grad will always return None).

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

dtypeOptional[DTypeLikeReals]

The dtype of the resulting tensor.

outOptional[Union[Tensor, ndarray]]

A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated tensor is returned.

whereMask

This condition is broadcast over the input. At locations where the condition is True, the out tensor will be set to the ufunc result. Elsewhere, the out tensor will retain its original value. Note that if an uninitialized out tensor is created via the default out=None, locations within it where the condition is False will remain uninitialized.

Returns:
reciprocalTensor

Notes

Note

This function is not designed to work with integers.

For integer arguments with absolute value larger than 1 the result is always zero because of the way Python handles integer division. For integer zero the result is an overflow.

References

Examples

>>> import mygrad as mg
>>> mg.reciprocal(2.)
Tensor(0.5)
>>> mg.reciprocal([1, 2., 3.33])
Tensor([ 1.       ,  0.5      ,  0.3003003])
Attributes:
identity
signature

Methods

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

Not implemented

at(indices[, b, constant])

Not implemented

outer(b, *[, dtype, out])

Not Implemented

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

Not Implemented

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

Not Implemented

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

Find the dtypes NumPy will use for the operation.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

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

Not implemented

at(indices[, b, constant])

Not implemented

outer(b, *[, dtype, out])

Not Implemented

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

Not Implemented

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

Not Implemented

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

Find the dtypes NumPy will use for the operation.

Attributes

identity

nargs

nin

nout

ntypes

signature

types