tensorflow常见函数——clip_by_value、numpy.random.RandomState、argmax
生活随笔
收集整理的這篇文章主要介紹了
tensorflow常见函数——clip_by_value、numpy.random.RandomState、argmax
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
常見簡單函數用法
- 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 第一次總結
以上是生活随笔為你收集整理的tensorflow常见函数——clip_by_value、numpy.random.RandomState、argmax的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tf.nn.conv2d()方法
- 下一篇: tf.train.exponential