remainder¶
- remainder(x1: array | int | float, x2: array | int | float, /) array¶
Returns the remainder of division for each element
x1_iof the input arrayx1and the respective elementx2_iof the input arrayx2.Note
This function is equivalent to the Python modulus operator
x1_i % x2_i.- Parameters:
x1 (Union[array, int, float]) – dividend input array. Should have a real-valued data type.
x2 (Union[array, int, float]) – divisor input array. Must be compatible with
x1(see Broadcasting). Should have a real-valued data type.
- Returns:
out (array) – an array containing the element-wise results. Each element-wise result must have the same sign as the respective element
x2_i. The returned array must have a data type determined by Type Promotion Rules.
Notes
At least one of
x1orx2must be an array.For input arrays which promote to an integer data type, the result of division by zero is unspecified and thus implementation-defined.
Special cases
Note
In general, similar to Python’s
%operator, this function is not recommended for floating-point operands as semantics do not follow IEEE 754. That this function is specified to accept floating-point operands is primarily for reasons of backward compatibility.For floating-point operands,
If either
x1_iorx2_iisNaN, the result isNaN.If
x1_iis either+infinityor-infinityandx2_iis either+infinityor-infinity, the result isNaN.If
x1_iis either+0or-0andx2_iis either+0or-0, the result isNaN.If
x1_iis+0andx2_iis greater than0, the result is+0.If
x1_iis-0andx2_iis greater than0, the result is+0.If
x1_iis+0andx2_iis less than0, the result is-0.If
x1_iis-0andx2_iis less than0, the result is-0.If
x1_iis greater than0andx2_iis+0, the result isNaN.If
x1_iis greater than0andx2_iis-0, the result isNaN.If
x1_iis less than0andx2_iis+0, the result isNaN.If
x1_iis less than0andx2_iis-0, the result isNaN.If
x1_iis+infinityandx2_iis a positive (i.e., greater than0) finite number, the result isNaN.If
x1_iis+infinityandx2_iis a negative (i.e., less than0) finite number, the result isNaN.If
x1_iis-infinityandx2_iis a positive (i.e., greater than0) finite number, the result isNaN.If
x1_iis-infinityandx2_iis a negative (i.e., less than0) finite number, the result isNaN.If
x1_iis a positive (i.e., greater than0) finite number andx2_iis+infinity, the result isx1_i. (note: this result matches Python behavior.)If
x1_iis a positive (i.e., greater than0) finite number andx2_iis-infinity, the result isx2_i. (note: this result matches Python behavior.)If
x1_iis a negative (i.e., less than0) finite number andx2_iis+infinity, the result isx2_i. (note: this results matches Python behavior.)If
x1_iis a negative (i.e., less than0) finite number andx2_iis-infinity, the result isx1_i. (note: this result matches Python behavior.)In the remaining cases, the result must match that of the Python
%operator.
Changed in version 2024.12: Added scalar argument support.