jax.numpy.copysign#
- jax.numpy.copysign(x1, x2, /)[source]#
Copies the sign of each element in
x2
to the corresponding element inx1
.JAX implementation of
numpy.copysign
.- Parameters:
x1 (ArrayLike) – Input array
x2 (ArrayLike) – The array whose elements will be used to determine the sign, must be broadcast-compatible with
x1
- Returns:
An array object containing the potentially changed elements of
x1
, always promotes to inexact dtype, and has a shape ofjnp.broadcast_shapes(x1.shape, x2.shape)
- Return type:
Examples
>>> x1 = jnp.array([5, 2, 0]) >>> x2 = -1 >>> jnp.copysign(x1, x2) Array([-5., -2., -0.], dtype=float32)
>>> x1 = jnp.array([6, 8, 0]) >>> x2 = 2 >>> jnp.copysign(x1, x2) Array([6., 8., 0.], dtype=float32)
>>> x1 = jnp.array([2, -3]) >>> x2 = jnp.array([[1],[-4], [5]]) >>> jnp.copysign(x1, x2) Array([[ 2., 3.], [-2., -3.], [ 2., 3.]], dtype=float32)