AI学习之路(9): 张量的常量1
来源:互联网 发布:茶叶网络连锁 编辑:程序博客网 时间:2024/06/07 05:27
上一次我们学习了张量的变量,在这一次来学习一下张量的常量,因为很多时候需要使用张量常量来初始化变量,并且产生一些常量是固定的初始化值,这样可以减少变量的出错,同时也提供很好的测试数据,比如产生一个正态分布的数据,又或者产生初始化为0值,或者1值等等。
tf.zeros(shape, dtype=tf.float32, name=None)
产生零值常量的张量类。
参数:
shape: 任何的整数列表对象,或者是1维的整数张量。
dtype: 产生元素的类型。
name: 产生元素的名称。
返回值:
生成一个所有元素都是0的张量。
例子:
#python 3.5.3 蔡军生 #http://edu.csdn.net/course/detail/2592 #import tensorflow as tf#创建张量变量x = tf.zeros([1], dtype=tf.float32)y = tf.zeros([3, 4], tf.int32)#显示它的值init_op = tf.global_variables_initializer()with tf.Session() as sess: sess.run(init_op) print(x.eval())print(y.eval())
输出结果:
====================== RESTART: D:/AI/sample/tf_1.17.py ======================
[ 0.]
[[0 0 0 0]
[0 0 0 0]
[0 0 0 0]]
>>>
创建两行十列的0常量
例子:
#python 3.5.3 蔡军生 #http://edu.csdn.net/course/detail/2592 #import tensorflow as tf#创建张量0常量x = tf.zeros([2,10], dtype=tf.float32)#显示它的值init_op = tf.global_variables_initializer()with tf.Session() as sess: sess.run(init_op)print(x.eval())
输出结果如下:
====================== RESTART: D:/AI/sample/tf_1.19.py ======================
[[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
>>>
tf.ones(shape, dtype=tf.float32, name=None)
创建一个所有元素都为1的张量常量。
参数:
shape: 任何整数的列表对象,或者是1维的整数(int32)张量。
dtype: 产生元素的数据类型。
name: 张量的名称。
返回值:
一个所有元素设置为1的张量常量。
例子:
#python 3.5.3 蔡军生 #http://edu.csdn.net/course/detail/2592 #import tensorflow as tf#创建张量常量x = tf.ones([2,10], dtype=tf.float32)#显示它的值init_op = tf.global_variables_initializer()with tf.Session() as sess: sess.run(init_op)print(x.eval())
输出结果:
1. C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
2.跟老菜鸟学C++
3. 跟老菜鸟学python
4. 在VC2015里学会使用tinyxml库
5. 在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
6.Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
7.在VC2015里使用protobuf协议
8.在VC2015里学会使用MySQL数据库
- AI学习之路(9): 张量的常量1
- AI学习之路(10): 张量的常量2
- AI学习之路(14): 张量的平方计算
- AI学习之路(11): 创建随机张量1
- AI学习之路(8): 定义张量变量
- AI学习之路(12): 创建随机张量2
- AI学习之路(13): 创建随机张量3
- AI学习之路(15): 张量不同数轴的平均值计算
- pytorch学习笔记(1)--pytorch张量
- Tensorflow学习笔记——张量、图、常量、变量(一)
- AI学习之路(6): NumPy的使用
- AI学习之路(21)卷积核的使用
- AI学习之路(1):TensorFlow在Windows安装
- AI学习之路(16): TensorFlow优化器1
- AI学习之路(一)
- 张量(tensor)的理解
- 张量(tensor)的基本概念
- (1)JS与AI 的学习
- 试探算法
- 微信浏览器
- 算法训练 数的划分
- 面向对象的程序设计Java-基本数据类型
- 食物链
- AI学习之路(9): 张量的常量1
- 走迷宫dfs
- Count the Sheep
- runtime基础、消息转发
- java安全架构____DES加密原理
- spring-aop注解配置
- Linux和windows环境下的Java开发的区别与不同
- dalvik机器码对照表
- BeautifulSoup 安装