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 [ ] 索引的更多相关文章

  1. 吴裕雄--天生自然TensorFlow2教程:高阶操作

    import tensorflow as tf a = tf.random.normal([3, 3]) a mask = a > 0 mask # 为True元素,即>0的元素的索引 i ...

  2. 吴裕雄--天生自然TensorFlow2教程:张量排序

    import tensorflow as tf a = tf.random.shuffle(tf.range(5)) a tf.sort(a, direction='DESCENDING') # 返回 ...

  3. 吴裕雄--天生自然TensorFlow2教程:创建Tensor

    import numpy as np import tensorflow as tf tf.convert_to_tensor(np.ones([2, 3])) tf.convert_to_tenso ...

  4. 吴裕雄--天生自然TensorFlow2教程:函数优化实战

    import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def himme ...

  5. 吴裕雄--天生自然TensorFlow2教程:数据统计

    import tensorflow as tf a = tf.ones([2, 2]) a tf.norm(a) tf.sqrt(tf.reduce_sum(tf.square(a))) a = tf ...

  6. 吴裕雄--天生自然TensorFlow2教程:维度变换

    图片视图 [b, 28, 28] # 保存b张图片,28行,28列(保存数据一般行优先),图片的数据没有被破坏 [b, 28*28] # 保存b张图片,不考虑图片的行和列,只保存图片的数据,不关注图片 ...

  7. 吴裕雄--天生自然TensorFlow2教程:Tensor数据类型

    list: [1,1.2,'hello'] ,存储图片占用内存非常大 np.array,存成一个静态数组,但是numpy在深度学习之前就出现了,所以不适合深度学习 tf.Tensor,为了弥补nump ...

  8. 吴裕雄--天生自然TensorFlow2教程:手写数字问题实战

    import tensorflow as tf from tensorflow import keras from keras import Sequential,datasets, layers, ...

  9. 吴裕雄--天生自然TensorFlow2教程:反向传播算法

随机推荐

  1. 158-PHP strstr函数输出第一次出现字符串的位置到字符串结尾的所有字符串

    <?php $str='PHP is a very good programming language!'; //定义一个字符串 echo '第一次出现字母l的位置到字符串结尾的所有字符串'.s ...

  2. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring通知类型及使用ProxyFactoryBean创建AOP代理

    通知(Advice)其实就是对目标切入点进行增强的内容,Spring AOP 为通知(Advice)提供了 org.aopalliance.aop.Advice 接口. Spring 通知按照在目标类 ...

  3. Node.js NPM 包(Package)

    章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json 包是打 ...

  4. Apache nifi 第二篇(小白初试) nifi数据对接流程初次尝试

     一.准备工作 1.官网下载nifi 2.上传到linux随便哪里把,因为nifi是用java写的,所以首先要保证你的linux装了jdk 其次保证系统在装了zookeeper,因为nifi是一个分布 ...

  5. App_显示图表内容

    今天在之前记账本的基础上增加了图标的显示功能,在本次课程中它以折线图为例讲述.但是课程中给出了多有图的代码案例. https://github.com/lecho/hellocharts-androi ...

  6. 原生js完成打地鼠小游戏

    :这是首页,有简单模式和地狱模式两种模式进行选择 这是选择完模式之后的游戏界面:30秒一局游戏倒计时,每打中一只老鼠加一分,没砸中减一分,没砸不加不减 首先准备几张图片 html代码: <!-- ...

  7. cf 261B.Maxim and Restaurant

    什么什么期望的,不会! (题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂)) #include<bits/stdc++.h ...

  8. cron 表达式0 0/10 * * * 与 0 */10 * * *的区别

    0 0/10 * * * 与 0 */10 * * * 的差别在于什么地方.在说这两者的差别之前,先说下各个字符代表的含义.0代表从0分开始,*代表任意字符,/代表递增. 0 0/10 * * *代表 ...

  9. Python pip换源

    前言 哈喽呀,小伙伴们,晚上好呀,今天要给大家带来点什么呐,我们就来说说python的pip换源吧,这个换源,相对来说,还是比较重要的,能少生好几次气的,哈哈哈 为什么要换源 我们搞python的,肯 ...

  10. Codeforces 1296C - Yet Another Walking Robot

    题目大意: 给定一个机器人的行走方式 你需要取走一段区间 但要保证取走这段区间后机器人最终到达的终点位置是不变的 问这段区间最短时是哪一段 解题思路: 易得,如果重复走到了某些已经走过的点,那么肯定就 ...