Tensorflow之数据类型
来源:互联网 发布:半岛雪人 mac 编辑:程序博客网 时间:2024/06/08 15:19
import tensorflow as tf#定义常量tf.string是字符串类型hello = tf.constant('Hello,world!', dtype=tf.string)sess=tf.Session()print(sess.run(hello))#定义常量tf.bool是布尔类型,如果改为‘false’就会报错,显示更改为字符串类型boolean = tf.constant(False, dtype=tf.bool)print(sess.run(boolean))#定义常量tf.int8,int16,int32,int64类型(有符号整形)int = tf.constant(100, dtype=tf.int8)print(sess.run(int))#定义常量tf.uint8,tf.uint16(无符号整形)uint = tf.constant(100, dtype=tf.uint8)print(sess.run(uint))#定义常量tf.float16,tf.float32,tf.float64,tf.double(浮点数)float = tf.constant(100, dtype=tf.float16)print(sess.run(float))#定义常量tf.complex64,tf.complex128(复数)complex = tf.constant(100, dtype=tf.complex64)print(sess.run(complex))
输出
b'Hello,world!'False100100100.0(100+0j)
(1)现在搞清楚int8如果数据越界怎么处理?
import tensorflow as tfint = tf.constant(1000, dtype=tf.int8)sess=tf.Session()print(sess.run(int))
实验结果:
-24
1000转化成二进制为
1111101000
在int8中,取后八个字节11101000第8个字节为1表示负数,负数值为1转化为0,0转化为1然后加1
00010111+1=00011000=24。
如果1000换成488输出结果一样。
(2)搞清楚uint8如果数据越界怎么处理?
import tensorflow as tfuint = tf.constant(1000, dtype=tf.uint8)sess=tf.Session()print(sess.run(uint))
实验结果
232
直接获取后8位转化成10进制为
11101000=232
tensorflow定义张量常量
import tensorflow as tften=tf.constant(-1.0,dtype=tf.float16)sess=tf.Session()print(sess.run(ten))tensor = tf.constant(-1.0, shape=[2, 3])print(sess.run(tensor))tensor=tf.constant(['b','a','c'],dtype=tf.string)print(sess.run(tensor))tensor=tf.constant([1,'a','c'])print(sess.run(tensor))
其中shape表示常量的形状,如果不指定,那么为-1.0,如果指定shape=[2,3]然后结果为
[[-1. -1. -1.]
[-1. -1. -1.]]
在定义张量的时候,dtype=tf.string表示张量里面的数值都为string
同一个张量里面的数据类型必须保持一致(跟java中list相同),如果没有一致,则会报错,tensor=tf.constant([1,’a’,’c’])就会报错。
阅读全文
0 0
- Tensorflow之数据类型
- tensorflow | 操作函数 和 数据类型
- 【Tensorflow】TensorFlow 入门之基本原理
- tensorflow 入门之 hello tensorflow
- Tensorflow中张量数据类型的转换
- Tensorflow之Mnist入门
- 解读tensorflow之rnn
- Tensorflow之CNN实践
- Tensorflow之旅
- tensorflow 之 while_loop
- tensorflow之过拟合
- TensorFlow之深入MNIST
- 解读tensorflow之rnn
- TensorFlow之卷积
- tensorflow 入门之MNIST
- TensorFlow之线性回归
- tensorflow入门之Session
- tensorflow入门之Variable
- 深度学习——提高网络性能(一)
- HDU 6092 Rikka with Subset(思维)
- Java实现CORS跨域请求
- 真正一键开启PPTP、L2TP两种VPN服务,经测试兼容centos 6 7 、ubuntu 14 16、debian 8,32位64位,一次爽到底!
- Hibernate学习之旅
- Tensorflow之数据类型
- 正则表达式学习之回溯与固态分组/php
- C#事件与委托
- Linux定时任务 备份数据库
- 系统安全分析与设计---网络安全与防火墙
- 类重复: com.actions.pcbatest.R 重复错误
- Linux
- 662. Maximum Width of Binary Tree(二叉树层次遍历,二叉树标序号)
- 自定义弹窗