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. Django——HttpResponse()

    HttpResponse(content, #返回给视图函数的内容 content_type=None,#返回给视图函数的类型 text/html文本.text/plain.css.js.xml.js ...

  2. jQuery原理系列-工具函数

    jquery源码中有很多精妙的实现,对于我们每天都在使用的东西,一定要知其原理,如果遇到不能使用jquery环境,也能自己封装原生的代码实现. 1.检测类型 众所周知typeof 不能用来检测数据,会 ...

  3. winfrom窗体的透明度

    在VS中创建一个Winform项目,其默认的窗体名称为 Form1. 在VS设计界面中对 Form1 的 Opacity 属性值设置为 50%. 没错,就这样就可以了. 方法2:            ...

  4. 开发者在行动-政府侧IT需求志愿者招募令(第一弹)

    京东云与AI推出了[应急资源信息发布平台],在打通物资供需的同时,各地政府及公益组织可发布疫情信息化产品开发及运维服务的IT需求,如疫情防控统计.物资供需信息收集等IT管理.需求通过评审后平台将帮助发 ...

  5. python画一只佩奇

    用python画一只佩奇 from turtle import* def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 sethead ...

  6. spring源码 ListableBeanFactory接口

    ListableBeanFactory接口表示这些Bean是可列表的 /* * Copyright 2002-2016 the original author or authors. * * Lice ...

  7. java04异常处理课堂总结

    一,动手动脑 1,请阅读并运行AboutException.java示例,然后通过后面的几页PPT了解Java中实现异常处理的基础知识. import javax.swing.*; class Abo ...

  8. TX2-刷机完成后安装程序ubuntu_linux命令&TX2学习总结

    Linux教程|菜鸟教程:http://www.runoob.com/linux/linux-tutorial.html 认识linux:ping命令:ping命令是常用的网络命令ping网关:pin ...

  9. kettle将csv文件导入数据库

    具体过程学习了: 1.连接数据库 2.添加新资源库 3.选择Other Repositories 4.选择Database Repository,第二个需要配置额外参数 5.连接数据库相关设置 6.连 ...

  10. 屏幕切换 onStart() onStop() onRestart() onDestroy()

    android:configChanges="orientation|keyboardHidden|screenSize"          //xml文件<activity ...