#!/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]]