📜  Python| tensorflow.math.angle() 方法

📅  最后修改于: 2022-05-13 01:55:30.476000             🧑  作者: Mango

Python| tensorflow.math.angle() 方法

TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

angle() 是 tensorflow 数学模块中的方法。此方法用于查找张量的元素明智参数。默认情况下,所有元素都被视为复数 (a+bi)。如果是实数复数部分(b)被认为是零。 atan2(b,a) 是此函数计算的参数。

Syntax:
tensorflow.math.angle(
    input, name
)

Argument:
1. input: It is a tensor. Allowed dtype for this tensor are  float, double, complex64, complex128.
2. name: It is an optional argument that defines the name for the operation.
 
Return:
It returns a tensor of type float32 or float64.

示例 1:

Python3
# importing the library
import tensorflow as tf
 
# initializing the constant tensor
a = tf.constant([-1.5 + 7.8j, 3 + 5.75j], dtype=tf.complex64)
 
# calculating the arguments
b = tf.math.angle(a)
 
# printing the argument tensor
print('Tensor: ',b)


Python3
# importing the library
import tensorflow as tf
 
# initializing the constant tensor
a = tf.constant([-1.5, 3 ], dtype=tf.float64)
 
# calculating the arguments
b = tf.math.angle(a)
 
# printing the argument tensor
print('Tensor: ',b)


输出:

Tensor:  tf.Tensor([1.7607845 1.0899091], shape=(2,), dtype=float32)

示例 2:

在实数的情况下,计算的参数始终为零。

Python3

# importing the library
import tensorflow as tf
 
# initializing the constant tensor
a = tf.constant([-1.5, 3 ], dtype=tf.float64)
 
# calculating the arguments
b = tf.math.angle(a)
 
# printing the argument tensor
print('Tensor: ',b)

输出:

Tensor:  tf.Tensor([0. 0.], shape=(2,), dtype=float64)