吴裕雄--天生自然TensorFlow2教程:numpy [ ] 索引
import tensorflow as tf a = tf.ones([1, 5, 5, 3])
a.shape a[0][0]
numpy : 索引 a = tf.random.normal([4, 28, 28, 3])
a.shape a[1].shape a[1, 2].shape
a[1][2][3].shape
a[1, 2, 3, 2].shape
一维切片
a = tf.range(10)
a a[-1:]
a[-2:]
a[:2]
a[:-1]
多维切片
a = tf.random.normal([4, 28, 28, 3])
a.shape a[0].shape a[0, :, :, :].shape a[0, 1, :, :].shape a[:, :, :, 0].shape a[:, :, :, 2].shape a[:, 0, :, :].shape
步长::step
a = tf.random.normal([4, 28, 28, 3])
a.shape a[0:2, :, :, :].shape a[:, 0:28:2, 0:28:2, :].shape a[:, :14, :14, :].shape a[:, 14:, 14:, :].shape a[:, ::2, ::2, :].shape
倒序::-1
a = tf.range(4)
a a[::-1] a[::-2] a[2::-2]
省略号...
a = tf.random.normal([2, 4, 28, 28, 3])
a.shape a[0].shape a[0, :, :, :, :].shape a[0, ...].shape a[:, :, :, :, 0].shape a[..., 0].shape a[0, ..., 2].shape a[1, 0, ..., 0].shape
gather a = tf.random.normal([4, 35, 8])
a.shape tf.gather(a, axis=0, indices=[2, 3]).shape a[2:4].shape tf.gather(a, axis=0, indices=[2, 1, 3, 0]).shape tf.gather(a, axis=1, indices=[2, 3, 7, 9, 16]).shape tf.gather(a, axis=2, indices=[2, 3, 7]).shape aa = tf.gather(a,axis,[several students])
aaa = tf.gather(aa,axis,[several subjects])
gather_nd a = tf.random.normal([4, 35, 8])
a.shape tf.gather_nd(a, [0]).shape # [[0],[],[]] tf.gather_nd(a, [0, 1]).shape tf.gather_nd(a, [0, 1, 2]).shape tf.gather_nd(a, [[0, 1, 2]]).shape tf.gather_nd(a, [[0, 0], [1, 1]]).shape tf.gather_nd(a, [[0, 0], [1, 1], [2, 2]]).shape # 第一个班级第一个学生的第一门课
# 第二个班级第二个学生的第二门课
# 第三个班级第三个学生的第三门课
tf.gather_nd(a, [[0, 0, 0], [1, 1, 1], [2, 2, 2]]).shape tf.gather_nd(a, [[[0, 0, 0], [1, 1, 1], [2, 2, 2]]]).shape
boolean_mask
a = tf.random.normal([4, 28, 28, 3])
a.shape tf.boolean_mask(a, mask=[True, True, False, False]).shape tf.boolean_mask(a, mask=[True, True, False], axis=3).shape a = tf.ones([2, 3, 4])
a.shape # [2,3],还剩下4,三个True,因此是3*4True
tf.boolean_mask(a, mask=[[True, False, False], [False, True, True]]).shape
吴裕雄--天生自然TensorFlow2教程:numpy [ ] 索引的更多相关文章
- 吴裕雄--天生自然TensorFlow2教程:高阶操作
import tensorflow as tf a = tf.random.normal([3, 3]) a mask = a > 0 mask # 为True元素,即>0的元素的索引 i ...
- 吴裕雄--天生自然TensorFlow2教程:张量排序
import tensorflow as tf a = tf.random.shuffle(tf.range(5)) a tf.sort(a, direction='DESCENDING') # 返回 ...
- 吴裕雄--天生自然TensorFlow2教程:创建Tensor
import numpy as np import tensorflow as tf tf.convert_to_tensor(np.ones([2, 3])) tf.convert_to_tenso ...
- 吴裕雄--天生自然TensorFlow2教程:函数优化实战
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...
- 吴裕雄--天生自然TensorFlow2教程:数据统计
import tensorflow as tf a = tf.ones([2, 2]) a tf.norm(a) tf.sqrt(tf.reduce_sum(tf.square(a))) a = tf ...
- 吴裕雄--天生自然TensorFlow2教程:维度变换
图片视图 [b, 28, 28] # 保存b张图片,28行,28列(保存数据一般行优先),图片的数据没有被破坏 [b, 28*28] # 保存b张图片,不考虑图片的行和列,只保存图片的数据,不关注图片 ...
- 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型
list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...
- 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战
import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...
- 吴裕雄--天生自然TensorFlow2教程:反向传播算法
随机推荐
- Hibernate--起步
1.配置对象 配置对象是你在任何 Hibernate 应用程序中创造的第一个 Hibernate 对象,并且经常只在应用程序初始化期间创造.它代表了 Hibernate 所需一个配置或属性文件.配置对 ...
- 九十五、SAP中查看自定义包的所有模块,对象,函数主,事务等
一.输入SE80 二.选择包,再查下Z* 三.可以看到,查下出来的包 四.可以看到我们想要的内容了
- 057-while循环
<?php $x=1; //初始化变量 while($x<=5){ //执行while循环 echo "$x<br />"; $x++; } ?>
- 最简单的前端获取后台的json值(后台怎么返回一个json对象到前台)
(说一下这个外部包jackson一般不用了,现在大家都用马云儿子的FastJson 下面服务器代码我就不改了大家随意用什么外部包)2019.1.14日改 我使用了外部包jackson(杰克逊哈哈哈啊) ...
- Django配置日志
在settings里配置 # 日志配置 LOGGING = { # 是python的版本 'version': 1, # 是否禁用 'disable_existing_loggers': False, ...
- Web基础之Servlet
Servlet Servlet : server applet,直译服务小程序.那Servlet到底是什么呢? Servlet说白了其实就是一个接口,接口的作用是什么?规范呗,这个接口规定了下面三个问 ...
- HDU - 4082 Hou Yi's secret
题意:射箭落在n个点,任取三点可构成一个三角形,问最大的相似三角形集(一组互相相似的三角形)的个数. 分析: 1.若n个点中有相同的点,要去重,题目中说射箭会形成洞,任选三个洞构成三角形,因此射在同一 ...
- 2016蓝桥杯省赛C/C++A组第八题 四平方和
题意: 四平方和定理,又称为拉格朗日定理: 每个正整数都可以表示为至多4个正整数的平方和. 如果把0包括进去,就正好可以表示为4个数的平方和. 比如: 5 = 0^2 + 0^2 + 1^2 + 2^ ...
- (转) Windows如何区分鼠标双击和两次单击
Windows如何区分鼠标双击和两次单击 http://lbsloveldm.blog.hexun.com/12212875_d.html 在Windows平台上,鼠标左键的按下.松开.快速的两次点击 ...
- Mac Go 环境变量配置
GOPATH 是工作目录,就是你打代码,代码的存放目录 GOROOT 是Go的安装目录,我下载的是免安装版的 现在的Go环境变量就是设置成这个样子, 终于Bee不会报错了!!!