tf.clip_by_value 用法

一个新手刚刚开始学习,各种坑。

tf.clip_by_value(V, min, max), 截取V使之在min和max之间

import tensorflow as tf

import numpy as np

v = tf.constant([[1.0, 2.0, 4.0],[4.0, 5.0, 6.0]])
result = tf.clip_by_value(v, 2.5, 4.5)


with tf.Session() as sess:

    print(sess.run(result))

输出

[[ 2.5  2.5  4. ]

 [ 4.   4.5  4.5]]

你可能感兴趣的:(function)