tensorflow 2.0 学习笔记 索引与切片

import tensorflow as tf

a=tf.random.normal([4,28,28,3])

a[1].shape

a[1,2].shape

a[1,2,3].shape

a[1,2,3,2].shape

''' start:end '''
b=tf.range(10)

b[-2:]

b[:3]

''' : 的运用-->全选 '''
a[:,0,:,:].shape

''' start:end:step  ::step '''
a[0:2,0:27:2,:,:]                                   #切片是左闭右开

a[:,::2,:,:]                                        #从0-27,步长为 2

''' 倒序采样 '''
b[::-2]                                             # 9,7,5,3,1

b[4::-2]                                            # 4,2,0

b[3::2]                                             # 3,5,7,9
b[3:9:2]                                            # 3,5,7  不能取到 最后一个元素

''' 省略号的运用 ... '''
a[0,...].shape

a[0,...,1].shape


''' tf.gather tf.gather_nd tf.boolean_mask '''

c=tf.random.normal([4,35,8])                       # 4个班级,每个班级35人,8个科目的成绩单

tf.gather(c,axis=0,indices=[0,2]).shape            # 1,3两班的成绩单

tf.gather_nd(c,[[0,1,2],[1,2,3]]).shape                 # 选取特定班级,学生,科目

tf.boolean_mask(a,mask=[True,False,True],axis=3).shape

d=tf.ones([2,3,4])
tf.boolean_mask(d,mask=[[True,True,False],[False,True,True]]).shape  # 4行4列

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值