• 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]]



  • 相关阅读:
    数列分段
    2020-01-21 数组 最大子序和
    2020-01-21 数组
    补 2020-01-20 数组 删除排序数组中的重复项
    补2020-01-19 数组 两数之和
    2020-01-18 刷题 螺旋矩阵 II
    2020-01-16 刷题 长度最小的子数组
    2020-01-15 刷题 移除元素
    2020-01-14 QT学习记录
    2020-01-14 数组刷题-1
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/12019548.html
Copyright © 2020-2023  润新知