吴裕雄--天生自然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教程:反向传播算法
随机推荐
- read和write函数的使用
https://blog.csdn.net/qq_33883085/article/details/88667003
- TensorFlow2 Part1:基础
TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经网络 ...
- 033-PHP对一个数组先奇后偶,然后再进行从大到小排序
<?php function Compare($str1, $str2) { if (($str1 % 2 == 0) && ($str2 %2 == 0)) { if ($st ...
- HDU 4901 多校4 经典计数DP
RT 最近不想写博客,累积了一周多的题目,今天趁着周日放假,全部补上吧 dp[i][j]表示前i个数,操作后的值为j的总个数 注意取或不取,有种完全背包的意味.因为数字小于1024,所以异或的结果也绝 ...
- mysql安装--window版
一.下载 二.解压 三.配置 四.环境变量 五.安装MySQL服务 六.启动MySQL服务 七.停止MySQL 一.下载 第一步:打开网址,https://www.mysql.com,点击downlo ...
- js实现鼠标单击或者双击事件
// timer为全局变量 getClickEmail1(_type) { clearTimeout(this.timer); if (_type == 1) { if (event.detail = ...
- 读书笔记 - js高级程序设计 - 第十章 DOM
文档元素 是文档的最外层元素,在Html页面中,文档元素始终都是<html>元素 在xml中,任何元素都可以是文档元素 Node类型 Node.ELEMENT_NODE 元素 Node ...
- RMAN > BACKUP VALIDATE DATABASE ARCHIVELOG ALL
使用BACKUP ... VALIDATE 命令: You can use the BACKUP VALIDATE command to do the following: (1)Che ...
- Dubbo与Zookeeper 简介
转自http://blog.csdn.net/congcong68/article/details/41113239 首先说一下Dubbo解决什么问题: (1)当服务越来越多时,服务Url配置管理变得 ...
- 在mysql中计算百分比
通过查找资料,得到了如下解决方法: 用到了concat()和left() 两个函数 1.CONCAT(str1,str2,...) 返回来自于参数连结的字符串.如果任何参数是NULL, 返回NULL. ...