tf.keras.ops.copysign

Compose a value from the magnitude of x1 and the sign of x2.

The sign of zero is taken into account, so an x2 of -0.0 gives a negative result and an x2 of 0.0 gives a positive one.

x1 Input tensor providing the magnitude.
x2 Input tensor providing the sign.

Output tensor with the magnitude of x1 and the sign of x2.

Example:

x1 = keras.ops.convert_to_tensor([-1.0, 2.0, -3.0])
x2 = keras.ops.convert_to_tensor([1.0, -1.0, -0.0])
keras.ops.copysign(x1, x2)
array([ 1., -2., -3.], dtype=float32)