add — Python array API standard 2024.12 documentation (original) (raw)

add(x1: array | int | float | complex, x2: array | int | float | complex, /) → array

Calculates the sum for each element x1_i of the input array x1 with the respective element x2_i of the input array x2.

Parameters:

Returns:

out (array) – an array containing the element-wise sums. The returned array must have a data type determined by Type Promotion Rules.

Notes

Special cases

For real-valued floating-point operands,

Note

Floating-point addition is a commutative operation, but not always associative.

For complex floating-point operands, addition is defined according to the following table. For real components a and c and imaginary components b and d,

c dj c + dj
a a + c a + dj (a+c) + dj
bj c + bj (b+d)j c + (b+d)j
a + bj (a+c) + bj a + (b+d)j (a+c) + (b+d)j

For complex floating-point operands, real-valued floating-point special cases must independently apply to the real and imaginary component operations involving real numbers as described in the above table. For example, let a = real(x1_i), b = imag(x1_i), c = real(x2_i), d = imag(x2_i), and

Hence, if z1 = a + bj = -0 + 0j and z2 = c + dj = -0 - 0j, the result of z1 + z2 is -0 + 0j.

Changed in version 2022.12: Added complex data type support.

Changed in version 2024.12: Added scalar argument support.