TenSorFlow-掩碼

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tensorflow as tf 
x = tf.constant(2)
y = tf.constant(20)
z = tf.Variable([[6,1,2],[3,4,5],[0,0,0],[8,2,4]])
mask=z[:,0]>0
res = tf.boolean_mask(z,mask)
init_assign = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init_assign)

    print sess.run(res)

運行結果:

[[6 1 2]
 [3 4 5]
 [8 2 4]]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章