當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tensorflow.math.conj()用法及代碼示例

TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。 conj()用於查找複數輸入張量的元素智能複共軛。

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

參數:

  • x:它是張量,並且必須具有數字值。
  • name(optional):它定義了操作的名稱。

返回值:
它返回與x相同dtype的張量。
如果輸入不是數字張量,它將引發TypeError。

範例1:



Python3

# 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輸入。

Python3

# 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)




相關用法


注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.conj()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。