Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

AI学习之路(11): 创建随机张量1

$
0
0

由于在测试的过程中,经常要产生一些不同分布的随机数,比如初始化待定的变量。又或者一些训练数据。因此来学习一步随机数的产生。

tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)

从正态分布创建随机张量。

参数 :

shape: 一维整数张量或者 python 数组

mean: 常数,表示正态分布的系数。

stddev: 常数,表示正态分布绝对偏差。

dtype: 输出张量的类型。

seed: Python 整数,用来产生随机的种子。

name: 张量的名称。

返回值 :

使用随机数据填充指定行列的张量。

例子:

#python 3.5.3 蔡军生 #http://edu.csdn.net/course/detail/2592 # import tensorflow as tf import matplotlib as mpl import matplotlib.pyplot as plt #绘制直方图 def drawHist(heights): #创建直方图 #第一个参数为待绘制的定量数据,不同于定性数据,这里并没有事先进行频数统计 #第二个参数为划分的区间个数 plt.hist(heights, 100) plt.xlabel('Value') plt.ylabel('Frequency') plt.title('Test') plt.show() #创建张量常量 x = tf.random_normal(shape=[20000],mean=0.0, stddev=1.0,dtype=tf.float32) #显示它的值 init_op = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init_op) print(x.eval()) drawHist(x.eval())

输出结果:


AI学习之路(11): 创建随机张量1
1. C++标准模板库从入门到精通

http://edu.csdn.net/course/detail/3324

2.跟老菜鸟学C++

Viewing all articles
Browse latest Browse all 9596

Trending Articles