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 第一次
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值