Basic Arithmetic Operations
numpy.add
x1, x2: array_like - The arrays to be added. Ifx1.shape != x2.shape, they must be broadcastable to a common shape.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
add: ndarray or scalar - The sum ofx1andx2, element-wise.
x1 + x2 in terms of array broadcasting.
Examples:
numpy.subtract
x1, x2: array_like - The arrays to be subtracted from each other.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray - The difference ofx1andx2, element-wise.
x1 - x2 in terms of array broadcasting.
Examples:
numpy.multiply
x1, x2: array_like - Input arrays to be multiplied.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray - The product ofx1andx2, element-wise.
x1 * x2 in terms of array broadcasting.
Examples:
numpy.divide
x1: array_like - Dividend array.x2: array_like - Divisor array.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray or scalar - The quotientx1/x2, element-wise.
x1 / x2 in terms of array broadcasting. The true_divide(x1, x2) function is an alias for divide(x1, x2).
Examples:
numpy.power
x1: array_like - The bases.x2: array_like - The exponents.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray - The bases inx1raised to the exponents inx2.
- An integer type raised to a negative integer power will raise a
ValueError. - Negative values raised to a non-integral value will return
nan. - To get complex results, cast the input to complex or specify
dtype=complex.
Modular Arithmetic
numpy.mod
numpy.remainder.
Parameters:
x1: array_like - Dividend array.x2: array_like - Divisor array.
y: ndarray - The element-wise remainder.
x1 % x2.
numpy.remainder
x1: array_like - Dividend array.x2: array_like - Divisor array.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray - The element-wise remainder of the quotientfloor_divide(x1, x2).
- Computes the remainder complementary to the
floor_dividefunction. - Equivalent to the Python modulus operator
x1 % x2and has the same sign as the divisorx2. - Returns 0 when
x2is 0 and bothx1andx2are integers. modis an alias ofremainder.
numpy.divmod
x1: array_like - Dividend array.x2: array_like - Divisor array.out: tuple of ndarrays, optional - A tuple of two arrays for output.where: array_like, optional - Condition to broadcast over the input.
out1: ndarray - Element-wise quotient.out2: ndarray - Element-wise remainder.
np.divmod(x, y) is equivalent to (x // y, x % y), but faster because it avoids redundant work. Used to implement Python’s built-in divmod function on NumPy arrays.
Examples:
Sign and Absolute Value
numpy.absolute
np.abs is a shorthand for this function.
Parameters:
x: array_like - Input array.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
absolute: ndarray - An ndarray containing the absolute value of each element inx.
- For real numbers:
- For complex numbers :
numpy.sign
x: array_like - Input values.out: ndarray, optional - A location into which the result is stored.where: array_like, optional - Condition to broadcast over the input.
y: ndarray - The sign ofx.
- Returns
-1ifx < 0 - Returns
0ifx == 0 - Returns
1ifx > 0 - Returns
nanfor nan inputs - For complex inputs: returns
x / abs(x)(and0ifx == 0)
See Also
Trigonometric Functions
sin, cos, tan, and their inverses
Exponential Functions
exp, log, and power functions
Rounding Functions
floor, ceil, round, and truncation
Special Functions
sqrt, square, gcd, and lcm
