Python ``tensorflow.math.conj()`` 复数共轭函数与实例


发布日期 : 2022-07-17 14:54:57 UTC

访问量: 10 次浏览

Python – tensorflow.math.conj()

TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。 conj() 用于寻找复数输入张量的明智复数。

语法:
tensorflow.math.conj( x, name)

参数:

  • x:它是一个张量,它必须有数字值。
  • name(可选)。它定义了操作的名称。

返回值:

它返回一个与x具有相同 dtype 的张量。

如果输入不是数字张量,它将引发TypeError。

示例 1:

# importing the library
import tensorflow as tf

# Initializing the input tensor
a = tf.constant([1+5j,3+2j,4+1j],dtype = tf.complex128)

# Printing the input tensor
print('a: ',a)

# Finding the complex conjugate
res = tf.math.conj(a)

# Printing the result
print('Complex Conjugate: ',res)

输出:

a: tf.Tensor([1.+5.j 3.+2.j 4.+1.j], shape=(3,), dtype=complex128)
Complex Conjugate: tf.Tensor([1.-5.j 3.-2.j 4.-1.j], shape=(3,), dtype=complex128)

例子2:
本例使用dtype float64的输入。

# importing the library
import tensorflow as tf

# Initializing the input tensor
a = tf.constant([1, 2, 3],dtype = tf.float64)

# Printing the input tensor
print('a: ',a)

# Finding the complex conjugate
res = tf.math.conj(a)

# Printing the result
print('Complex Conjugate: ',res)

输出:

a: tf.Tensor([1. 2. 3.], shape=(3,), dtype=float64)
Complex Conjugate: tf.Tensor([1. 2. 3.], shape=(3,), dtype=float64)