numpy.divide(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'divide'>
Divide arguments element-wise.
Parameters: |
x1 : array_like Dividend array. x2 : array_like Divisor array. out : ndarray, None, or tuple of ndarray and None, optional A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or where : array_like, optional Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone. **kwargs For other keyword-only arguments, see the ufunc docs. |
---|---|
Returns: |
y : ndarray or scalar The quotient |
See also
seterr
Equivalent to x1
/ x2
in terms of array-broadcasting.
Behavior on division by zero can be changed using seterr
.
In Python 2, when both x1
and x2
are of an integer type, divide
will behave like floor_divide
. In Python 3, it behaves like true_divide
.
>>> np.divide(2.0, 4.0) 0.5 >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> np.divide(x1, x2) array([[ NaN, 1. , 1. ], [ Inf, 4. , 2.5], [ Inf, 7. , 4. ]])
Note the behavior with integer types (Python 2 only):
>>> np.divide(2, 4) 0 >>> np.divide(2, 4.) 0.5
Division by zero always yields zero in integer arithmetic (again, Python 2 only), and does not raise an exception or a warning:
>>> np.divide(np.array([0, 1], dtype=int), np.array([0, 0], dtype=int)) array([0, 0])
Division by zero can, however, be caught using seterr
:
>>> old_err_state = np.seterr(divide='raise') >>> np.divide(1, 0) Traceback (most recent call last): File "<stdin>", line 1, in <module> FloatingPointError: divide by zero encountered in divide
>>> ignored_states = np.seterr(**old_err_state) >>> np.divide(1, 0) 0
© 2008–2017 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.divide.html