tf.nn.relu()函数是将大于0的数保持不变,小于0的数置为0
a = tf.constant([-1.0, 2.0])
with tf.Session() as sess:
b = tf.nn.relu(a)
print (sess.run(b))
输出
再举个例子吧:
import tensorflow as tf
a = tf.constant([[-2,-4],[4,-2]])
with tf.Session() as sess:
print(sess.run(tf.nn.relu(a)))
输出: