numpy - 获取满足条件tensorflow的张量行
问题描述
input_mb = tf.placeholder(tf.int32, [None, 166, 1], name="input_minibatch")
假设有上面的代码。我想获得上述小批量张量的行,使得每个检索到的行的第一个元素 == a。我如何在 Tensorflow 中做到这一点?另外,你如何在 Numpy 中做到这一点?
解决方案
(给定一个值 a)
要在numpy中实现这一点,您只需编写:
selected_rows = myarray[myarray[:,0]== a]
在tensorflow中,使用 tf.where :
mytensor[tf.squeeze(tf.where(tf.equal(mytensor[:,0],a), None, None))
推荐阅读
- javascript - React-Redux:尝试导入错误:'./components/Score' 不包含默认导出(导入为'Score')
- python - 大家好,你建议在空的for循环之后放什么(我不知道放什么)?
- java - javax/xml/bind/JAXBException
- leaflet - 如何使用传单?
- c# - 带有浮点值的 Unity 枚举下拉列表
- apache - .htaccess 子域的端口重写
- javascript - 如何使用 Python 和 Selenium 从外部 Javascript 文件执行函数?
- html - 让视频在 iphone/mobile 上内联工作
- python-3.x - apache_beam.io.WriteToText() 文件名作为模板参数
- c++ - 大括号 {} 的 Visual Code C/C++ 格式