TensorFlow索引与切片语句
学习课程
1.Basic indexing
a=tf.ones([1,5,5,3]) #创建tensor
a[0][0] #结果是5*3的tensor
a[0][0][0] #结果是1*3的tensor
a[0][0][0][1] #结果是一个数1
2.Numpy-style indexing
a = tf.random.normal([4,28,28,3]) #4张照片
a[1].shape #第2张照片的信息维度,TensorShape([28,28,3])
a[1,2].shape #第二张照片第三行的信息维度,TensorShape([28,3])
a[1,2,3].shape #第二张照片第三行第四列的信息维度TensorShape([3])
a[1,2,3,2].shape #第二张照片第三行第四列地三层的信息维度TensorShape([])
3.start:end #左闭右开
a=tf.range(10)
a[-1:] #结果为[9]
a[-2:] #结果为[8,9]
a[1:] #结果为[1,2,3,4,5,6,7,8,9]
a[:-1] #结果为[0,1,2,3,4,5,6,7,8]
4.Indexing by :
a = tf.random.normal([4,28,28,3]) #4张照片
a[0].shape #第1张照片的信息维度,TensorShape([28,28,3])
a[0,:,:,:].shape #第1张照片的信息维度,TensorShape([28,28,3])
a[0,1,:,:].shape #第1张照片第1行的信息维度,TensorShape([28,3])
a[:,:,:,2].shape #第三层信息维度,TensorShape([4,28,28])
a[:,0,:,:].shape #第1行信息维度,TensorShape([4,28,3])
5.Indexing by ::
start: end:step
::step
a[0:2,:,:,:].shape #TensorShape([2,28,28,3])
a[:,0:28:2,:,:].shape #TensorShape([4,14,28,3])
a[:,:14,:,:].shape #TensorShape([4,14,28,3])
a[:,:14,14:,:].shape #TensorShape([4,14,14,3])
a[:,::2,::2,:].shape #TensorShape([4,14,14,3])
6.::-1 #逆序
a=tf.range(4) #[0,1,2,3]
a[::-1] #[3,2,1,0]
a[::-2] #[3,1]
a[2::-2] #[2,0]
7.…
a = tf.random.normal([2,4,28,28,3]) #,2个tasts,4张照片
a[0].shape #TensorShape([4,28,28,3])
a[0,:,:,:,:].shape #TensorShape([4,28,28,3])
a[0,...].shape #TensorShape([4,28,28,3])
a[:,:,:,:,0].shape #TensorShape([2,4,28,28])
a[...,0].shape #TensorShape([2,4,28,28])
a[0,:,:,:,0].shape #TensorShape([4,28,28])
a[0,...,0].shape #TensorShape([4,28,28])
8.tf.gather
a=tf.random.normal([4,35,8]) #4个班级,每个班级35个学生,每个学生8科课程
tf.gather(a,axis=0,indices[2,3]).shape #TensorShape([2,35,8]),选第3和第4个班级的所有数据
a[2:4].shape #TensorShape([2,35,8]),选第3和第4个班级的所有数据
tf.gather(a,axis=0,indices[3,2,4,1]).shape #TensorShape([4,35,8]),所有班级所有数据,但班级查看顺序不一样
tf.gather(a,axis=1,indices[2,4,7]).shape #TensorShape([4,3,8]),所有班级的第3,5,8号学生的所有科目成绩
9.tf.gather_nd
略
10.tf.boolean_mask
略
TensorFlow索引与切片语句相关推荐
- 深度学习(7)TensorFlow基础操作三: 索引与切片
深度学习(7)TensorFlow基础操作三: 索引与切片 一. 基础索引 1. Basic indexing 2. Numpy-style indexing 3. start : end 4. 切片 ...
- 【TensorFlow】——索引与切片
目录 1.利用index进行索引 2.利用":"和"..."进行索引与切片 3.tf.gather()--对一个维度进行乱序索引 优势: 缺点: 例子 4.tf ...
- 08_索引与切片,Indexing,Python风格的索引,index_select()选择特定索引,使用...索引任意多的维度,使用mask索引,take索引
1.8.索引与切片 1.8.1.Indexing 1.8.2.Python风格的索引 1.8.3.index_select()选择特定索引 1.8.4.使用-索引任意多的维度 1.8.5.使用mask ...
- c++没有终结符的多行输入如何停止_如何使用iloc和loc 对Pandas Dataframe进行索引和切片...
在这篇文章中,我们将使用iloc和loc来处理数据.更具体地说,我们将通过iloc和loc例子来学习切片和索引. 一旦我们将一个数据集加载为Pandas dataframe,我们通常希望根据某些条件开 ...
- dataframe iloc_如何使用iloc和loc 对Pandas Dataframe进行索引和切片
在这篇文章中,我们将使用iloc和loc来处理数据.更具体地说,我们将通过iloc和loc例子来学习切片和索引. 一旦我们将一个数据集加载为Pandas dataframe,我们通常希望根据某些条件开 ...
- numpy 索引和切片
目录 1. 索引元素 2. 切片 省略参数写法 3. 应用举例 4. 多维数组 二维数组获取一行 二维数组获取一列 5. 多维数组的切片 如果要获取,第一行的第四和第五个元素: 如果得到数组的最后两行 ...
- Series索引、切片
一. Series 位置索引 位置索引,从0开始数,[0]是series第一个数,[1]是series第二个数 series不能[-1]定位索引 In [1]:s = pd.Series(np.ran ...
- Pandas-数据结构-Series(二):Series的索引【下标索引、标签索引、切片索引、布尔型索引】
一.下标索引 位置下标,类似序列 位置下标从0开始 输出结果为numpy.float格式, 可以通过float()函数转换为python float格式 numpy.float与float占用字节不同 ...
- python中iloc切片_如何使用iloc和loc 对Pandas Dataframe进行索引和切片
Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 在这篇文章中,我们将使用iloc和loc来处理数据.更具体地说,我们将通过iloc和loc例子来学习切片和 ...
最新文章
- 零起点学算法24——求正弦和余弦
- sizeof计算类大小
- 关于Facebook iOS UI 工具ComponentKit简介
- 你应该知道的15个Silverlight诀窍
- 开发日记-20190529 关键词 读书笔记《鸟哥的Linux私房菜-基础学习篇》
- 学python语言用什么软件-Python是什么?学习Python用什么编译器?
- java 枚举类 enum
- mmap mprotect详解
- 音视频技术开发周刊 87期
- java 录音_用JAVA实现不限时录音功能
- JDK8新特性(一)之Lambda表达式
- vue组件制作专题 - (mpvue专用)在mpvue中纯自己写css实现简单左右轮播
- Java web项目目录结构以及作用详解
- python获取arduino数据可视化_Arduino数据可视化在实验教学中的应用
- weui学习总结——1、weui表单常用标签
- webpack中的chunk
- Pulmonary--Detection5
- 用java简单写一个信息管理系统(尚硅谷项目二)
- SQL2005断电重启数据库置疑修复成功案例
- 小火狐进化_神奇宝贝第一到第八代中,小智不拥有的御三家是哪几只?
热门文章
- a, b = b, a+b
- java设计模式--观察者模式(Observer)
- 计算图像相似度——《Python也可以》之一(转)
- 网络抓包工具wireshark and tcpdump 及其实现基于的libpcap
- 简单数据分布分析及python实现
- Hyperledger Fabric 核心模块(2)configtxgen configtx.yaml配置文件
- 近世代数--内外直积--本质是一样的
- 【笔记】公钥密码学之RSA
- [How TO]-How to install maven
- [gic]-ARM gicv3/gicv4的详细介绍-2020/08