tf.keras.ops.arctan2
Stay organized with collections
Save and categorize content based on your preferences.
Element-wise arc tangent of x1/x2
choosing the quadrant correctly.
tf.keras.ops.arctan2(
x1, x2
)
The quadrant (i.e., branch) is chosen so that arctan2(x1, x2)
is the
signed angle in radians between the ray ending at the origin and passing
through the point (1, 0)
, and the ray ending at the origin and passing
through the point (x2, x1)
. (Note the role reversal: the "y-coordinate"
is the first function parameter, the "x-coordinate" is the second.) By IEEE
convention, this function is defined for x2 = +/-0
and for either or both
of x1
and x2
= +/-inf
.
Args |
x1
|
First input tensor.
|
x2
|
Second input tensor.
|
Returns |
Tensor of angles in radians, in the range [-pi, pi] .
|
Examples:
Consider four points in different quadrants:
>>> x = keras.ops.convert_to_tensor([-1, +1, +1, -1])
>>> y = keras.ops.convert_to_tensor([-1, -1, +1, +1])
>>> keras.ops.arctan2(y, x) * 180 / numpy.pi
array([-135., -45., 45., 135.], dtype=float32)
Note the order of the parameters. arctan2
is defined also when x2=0 and
at several other points, obtaining values in the range [-pi, pi]
:
>>> keras.ops.arctan2(
... keras.ops.array([1., -1.]),
... keras.ops.array([0., 0.]),
... )
array([ 1.5707964, -1.5707964], dtype=float32)
>>> keras.ops.arctan2(
... keras.ops.array([0., 0., numpy.inf]),
... keras.ops.array([+0., -0., numpy.inf]),
... )
array([0., 3.1415925, 0.7853982], 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 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.arctan2\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/numpy.py#L748-L789) |\n\nElement-wise arc tangent of `x1/x2` choosing the quadrant correctly.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.ops.numpy.arctan2`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/arctan2)\n\n\u003cbr /\u003e\n\n tf.keras.ops.arctan2(\n x1, x2\n )\n\nThe quadrant (i.e., branch) is chosen so that `arctan2(x1, x2)` is the\nsigned angle in radians between the ray ending at the origin and passing\nthrough the point `(1, 0)`, and the ray ending at the origin and passing\nthrough the point `(x2, x1)`. (Note the role reversal: the \"y-coordinate\"\nis the first function parameter, the \"x-coordinate\" is the second.) By IEEE\nconvention, this function is defined for `x2 = +/-0` and for either or both\nof `x1` and `x2` `= +/-inf`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------|----------------------|\n| `x1` | First input tensor. |\n| `x2` | Second input tensor. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Tensor of angles in radians, in the range `[-pi, pi]`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\nConsider four points in different quadrants: \n\n \u003e\u003e\u003e x = keras.ops.convert_to_tensor([-1, +1, +1, -1])\n \u003e\u003e\u003e y = keras.ops.convert_to_tensor([-1, -1, +1, +1])\n \u003e\u003e\u003e keras.ops.arctan2(y, x) * 180 / numpy.pi\n array([-135., -45., 45., 135.], dtype=float32)\n\nNote the order of the parameters. `arctan2` is defined also when x2=0 and\nat several other points, obtaining values in the range `[-pi, pi]`: \n\n \u003e\u003e\u003e keras.ops.arctan2(\n ... keras.ops.array([1., -1.]),\n ... keras.ops.array([0., 0.]),\n ... )\n array([ 1.5707964, -1.5707964], dtype=float32)\n \u003e\u003e\u003e keras.ops.arctan2(\n ... keras.ops.array([0., 0., numpy.inf]),\n ... keras.ops.array([+0., -0., numpy.inf]),\n ... )\n array([0., 3.1415925, 0.7853982], dtype=float32)"]]