tf生成一定范围的均匀分布的随机矩阵

在word2vec训练的时候,生成处理随机词向量的时候,可以根据tf.random_uniform()获取随机矩阵。

#-*-coding:utf8-*-
import tensorflow as tf

with tf.Session() as sess:
	print(sess.run(tf.random_uniform(
		(4, 4), minval=-1,
		maxval=1, dtype=tf.float32)))
实验结果:

"C:\Program Files\Anaconda3\python.exe" C:/Users/User/PycharmProjects/nlpdemo/word2vec/test_random_uniform.py
2018-01-09 11:04:04.450100: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
[[ 0.66339421 -0.11007571  0.06089711 -0.2449348 ]
 [ 0.92638063 -0.21169639 -0.77011728 -0.75142145]
 [ 0.82014132  0.24973822 -0.56280303 -0.15671754]
 [ 0.2885654  -0.05570364  0.14831567  0.39260006]]

Process finished with exit code 0



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值