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


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

TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。

is_inf()如果元素是無限的,則返回true,否則返回false。

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

參數:

  • x:它是張量。允許的dtypes是bfloat16,half,float32,float64。
  • name(optional):它定義了操作的名稱

返回值:它返回dtype bool的張量。



範例1:

Python3

# importing the library 
import tensorflow as tf 
import numpy as np 
  
# Initializing the input tensor 
a = tf.constant([7, 8, 13, 11, np.inf], dtype = tf.float64) 
  
# Printing the input tensor 
print('a:', a) 
  
# Calculating the result 
res = tf.math.is_inf(a) 
  
# Printing the result 
print('Result:', res)

輸出:

a: tf.Tensor([ 7.  8. 13. 11. inf], shape=(5, ), dtype=float64)
Result: tf.Tensor([False False False False  True], shape=(5, ), dtype=bool)


範例2:本示例使用numpy nan並檢查其無限性。

Python3

# Importing the libraray 
import tensorflow as tf 
import numpy as np 
  
# Initializing the input tensor 
a = tf.constant([7, 8, 13, 11, np.nan], dtype = tf.float64) 
  
# Printing the input tensor 
print('a:', a) 
  
# Calculating the result 
res = tf.math.is_inf(a) 
  
# Printing the result 
print('Result:', res)

輸出:

a: tf.Tensor([ 7.  8. 13. 11. nan], shape=(5, ), dtype=float64)
Result: tf.Tensor([False False False False False], shape=(5, ), dtype=bool)



相關用法


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