xp_copysign¶
- xp_copysign(x1: Any, x2: Any, /, *, xp: ModuleType | None = None) Any[source][source]¶
Copy the sign of x2 to the magnitude of x1.
- Parameters:
x1 (
Array) – The array containing the magnitudes.x2 (
Array) – The array containing the signs.xp (
module, optional) –- The array API namespace to use. If not provided, the namespace is
inferred from the arrays.
- Returns:
An array with the magnitude of x1 and the sign of x2.
- Return type:
Array
Notes
- This is a temporary substitute for xp.copysign, which is not yet available
- in all backends or covered by array_api_compat. This implementation does
not attempt to account for special cases.
Examples
>>> import numpy as np >>> x1 = np.array([-1.3, 1.5, -3.0]) >>> x2 = np.array([1.0, -2.2, 3.0]) >>> xp_copysign(x1, x2, xp=np) array([ 1.3, -1.5, 3. ]) >>> # Equivalent to NumPy's copysign >>> np.copysign(x1, x2) array([ 1.3, -1.5, 3. ])