Tensor数据类型
Tensor数据类型
- list: [1,1.2,'hello'] ,存储图片占用内存非常大
- np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习
- tf.Tensor,为了弥补numpy的缺点,更多的是为了深度学习而生
- tensor:
- scalar:标量,1.1
- vector:向量,[1.1],[1.1,2.2,...]
- matrix: 矩阵,[[1.1,2.2],[3.3,4.4]]
- tensor:rank>2
- 数据类型:
- Int, float, double
- bool
- string
- 定义tensor
tf.constant(1) # 定义常量,普通的tensor
tf.constant(1.) # 定义常量,普通的tensor
tf.constant([True, False]) # 定义常量,普通的tensor
tf.constant('hello nick')
属性
with tf.device('cpu'):
a = tf.constant([1])
with tf.device('gpu'):
b = tf.constant([1])
a.device # 设备属性
a.gpu() # cpu转gpu
a.numpy() # 获取numpy数据类型
a.shape # 获取a的属性
a.ndim # 获取维度
tf.rank(a) # 获取维度
a.name # 1.+历史遗留问题
数据类型判断
instance(a,tf.Tensor) # 判断是否为tensor
tf.is_tensor(a) # 判断是否为tensor
a.dtype,b.dtype,c.dtype # 判断数据类型
数据类型转换
a = np.arange(5)
aa = tf.convert_to_tensor(a,dtype=tf.int32) # numpy转tensor
tf.cast(aa,dtype=tf.float32) # tensor之间数据类型转换
# int --》 bool
b = tf.constant([0,1])
tf.cast(b,dtype=tf.bool) # int --》bool
# tf.Variable
a = tf.range(5)
b = tf.Variable(a) # tensor转为Variable后具有求导的特性,即自动记录a的梯度相关信息
b.name # Variable:0
b = tf.Variable(a, name='input_data')
b.name # input_data:0
b.trainable # True
isinstance(b,tf.Tensor) # False
isinstance(b,tf.Variable) # True
tf.is_tensor(b) # True # 推荐使用
tensor转numpy
a= tf.range(5)
a.numpy()
# a必须是scalar
a = tf.ones([])
a.numpy()
int(a)
float(a)
Tensor数据类型的更多相关文章
- Pytorch的tensor数据类型
基本类型 torch.Tensor是一种包含单一数据类型元素的多维矩阵. Torch定义了七种CPU tensor类型和八种GPU tensor类型: Data tyoe CPU tensor GPU ...
- 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...
- [Pytorch]Pytorch的tensor变量类型转换
原文:https://blog.csdn.net/hustchenze/article/details/79154139 Pytorch的数据类型为各式各样的Tensor,Tensor可以理解为高维矩 ...
- pytorch入坑一 | Tensor及其基本操作
由于之前的草稿都没了,现在只有重写…. 我好痛苦 本章只是对pytorch的常规操作进行一个总结,大家看过有脑子里有印象就好,知道有这么个东西,需要的时候可以再去详细的看,另外也还是需要在实战中多运用 ...
- pytorch中tensor张量数据基础入门
pytorch张量数据类型入门1.对于pytorch的深度学习框架,其基本的数据类型属于张量数据类型,即Tensor数据类型,对于python里面的int,float,int array,flaot ...
- 05_pytorch的Tensor操作
05_pytorch的Tensor操作 目录 一.引言 二.tensor的基础操作 2.1 创建tensor 2.2 常用tensor操作 2.2.1 调整tensor的形状 2.2.2 添加或压缩t ...
- Tensor基本理论
Tensor基本理论 深度学习框架使用Tensor来表示数据,在神经网络中传递的数据均为Tensor. Tensor可以将其理解为多维数组,其可以具有任意多的维度,不同Tensor可以有不同的数据类型 ...
- Tensor基础实践
Tensor基础实践 飞桨(PaddlePaddle,以下简称Paddle)和其他深度学习框架一样,使用Tensor来表示数据,在神经网络中传递的数据均为Tensor. Tensor可以将其理解为多维 ...
- 学习笔记TF048:TensorFlow 系统架构、设计理念、编程模型、API、作用域、批标准化、神经元函数优化
系统架构.自底向上,设备层.网络层.数据操作层.图计算层.API层.应用层.核心层,设备层.网络层.数据操作层.图计算层.最下层是网络通信层和设备管理层.网络通信层包括gRPC(google Remo ...
随机推荐
- bzoj 2142: 礼物【中国剩余定理+组合数学】
参考:http://blog.csdn.net/wzq_qwq/article/details/46709471 首先推组合数,设sum为每个人礼物数的和,那么答案为 \[ ( C_{n}^{sum} ...
- P3158 [CQOI2011]放棋子
传送门 题解(因为公式太多懒得自己抄写一遍了--) //minamoto #include<bits/stdc++.h> #define ll long long #define R re ...
- mysql 状态查询
select COUNT(case when info.State = '0' then State end ) as daichuliCount, COUNT(case when info.St ...
- 【SpringCloud构建微服务系列】使用Spring Cloud Config统一管理服务配置
一.为什么要统一管理微服务配置 对于传统的单体应用而言,常使用配置文件来管理所有配置,比如SpringBoot的application.yml文件,但是在微服务架构中全部手动修改的话很麻烦而且不易维护 ...
- Qt事件系统之一:Qt中的事件处理与传递
一.简介 在Qt中,事件作为一个对象,继承自 QEvent 类,常见的有键盘事件 QKeyEvent.鼠标事件 QMouseEvent 和定时器事件 QTimerEvent 等,与 QEvent 类的 ...
- 题解报告:hdu1202The calculation of GPA(算绩点问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1202 Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对 ...
- Windowsforms 中 进程,线程
进程: 进程是一个具有独立功能的程序关于某个数据集合的一次运行活动. 它可以申请和拥有系统资源,是一个动态的概念,是一个活动的实体. Process 类,用来操作进程. 命名空间:using Syst ...
- 学习笔记 第七章 使用CSS美化超链接
第7章 使用CSS美化超链接 学习重点 认识超链接 熟悉伪类 定义超链接样式 能够灵活设计符合页面风格的链接样式 7.1 定义超链接 在HTML5中建立超链接需要两个要素:设置为超链接的网页元素和 ...
- AlertDialog的实现
课程Demo 重点解析自定义对话框 public class MainActivity extends AppCompatActivity { private Button bt1; private ...
- ESSENTIALS OF PROGRAMMING LANGUAGES (THIRD EDITION) :编程语言的本质 —— (一)
# Foreword> # 序 This book brings you face-to-face with the most fundamental idea in computer prog ...