常见简单函数用法
- tf.clip_by_value()
tf.clip_by_value(V, min, max)
功能:截取在V,使V里面的各个元素在min和max之间
具体代码用法
import tensorflow as tf
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]]
'''
- numpy.random.RandomState()
numpy.random.RandomState(None|int)
功能:产生随机数种子
具体代码用法
import numpy
for i in [1,2,3,4]:
a = numpy.random.RandomState(None)
b = a.rand(1,2)
print(i)
print(b)
for i in [1,2,3,4]:
a = numpy.random.RandomState(1)
b = a.rand(1,2)
print(i)
print(b)
# 结果输出如下
'''
1
[[ 0.63678388 0.53997544]]
2
[[ 0.88420701 0.11569489]]
3
[[ 0.55099434 0.9790908 ]]
4
[[ 0.6769419 0.42401973]]
1
[[ 0.417022 0.72032449]]
2
[[ 0.417022 0.72032449]]
3
[[ 0.417022 0.72032449]]
4
[[ 0.417022 0.72032449]]
'''
- tf.argmax()
tf.argmax(input,dimension=None,name=None)
功能:返回沿dimension最大值的索引
具体代码用法
import tensorflow as tf
val = tf.constant([[1,2,3],[4,5,6]])
valShape = tf.shape(val)
t = tf.argmax(val,1)
with tf.Session() as sess:
result, shape = sess.run([t,valShape])
print(result)
print("shape = %s" % shape)
#输出结果如下
'''
[2 2]
shape = [2 3]
'''
参考
https://blog.csdn.net/qq_41694195/article/details/79573494
https://blog.csdn.net/william_hehe/article/details/78635815
https://blog.csdn.net/m0_37041325/article/details/77159660
记录日期
2018/9/11 19:50 第一次