tf.keras.ops.copysign
Stay organized with collections
Save and categorize content based on your preferences.
Compose a value from the magnitude of x1 and the sign of x2.
tf.keras.ops.copysign(
x1, 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.
Args |
x1
|
Input tensor providing the magnitude.
|
x2
|
Input tensor providing the sign.
|
Returns |
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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[null,null,["Last updated 2026-10-31 UTC."],[],[]]