tf.where()函數的解析


tf.where()的使用,該函數會返回滿足條件的索引。經驗證,發現返回均是二維矩陣,可以說明該函數用二維
矩陣給出滿足條件的位置索引。(若有錯誤,歡迎指正。)

代碼如下:
import tensorflow as tf
sess=tf.Session()
import numpy as np
print('驗證一維矩陣,tf.where()返回的索引:')
target_class_ids=np.array([4,5,3,6,2])
positive_roi_ix = tf.where(target_class_ids > 0)
positive_roi_ix=sess.run(positive_roi_ix)
print(positive_roi_ix)
print('驗證三維矩陣,tf.where()返回的索引:')
target_class_ids=np.array([[4,5,3,6,2],[4,5,3,6,-2]])
positive_roi_ix = tf.where(target_class_ids > 0)
positive_roi_ix=sess.run(positive_roi_ix)
print(positive_roi_ix)
print('驗證三維矩陣,tf.where()返回的索引:')
target_class_ids=np.array([[[4,5,3,6,2],[4,5,3,6,-2]],[[4,5,3,6,2],[4,5,3,6,-2]]])
positive_roi_ix = tf.where(target_class_ids > 0)
positive_roi_ix=sess.run(positive_roi_ix)
print(positive_roi_ix)

結果如下:

驗證一維矩陣,tf.where()返回的索引:
[[0]
[1]
[2]
[3]
[4]]
驗證三維矩陣,tf.where()返回的索引:
[[0 0]
[0 1]
[0 2]
[0 3]
[0 4]
[1 0]
[1 1]
[1 2]
[1 3]]
驗證三維矩陣,tf.where()返回的索引:
[[0 0 0]
[0 0 1]
[0 0 2]
[0 0 3]
[0 0 4]
[0 1 0]
[0 1 1]
[0 1 2]
[0 1 3]
[1 0 0]
[1 0 1]
[1 0 2]
[1 0 3]
[1 0 4]
[1 1 0]
[1 1 1]
[1 1 2]
[1 1 3]]




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM