• tensorflow切片


     

     

     

    #gather相当于收集
    #data[classes,studets,objects] #班级、学生、课程
    a=[4,35,8]
    tf.gather(a,axis=0,indices=[2,3]).shape#axis取那个维度0表示classes班级,indices获取班级具体索引[2,3]
    #[2,35,8] #表示从a获取第一列的2-3俩个班级,35人,没人8门课
    
    #对第axis个维度,进行采样,可以乱序
    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]]
    
    tf.gather_nd(a,[0]).shape #第0号班级的学生和课程
    tf.gather_nd(a,[0,1]).shape# 0号班级的第一号学生的课程
    tf.gather_nd(a,[0,1,2]).shape #0号班级,第一个学生的第2门课程,就是[]
    tf.gather_nd(a,[[0,1,2]]).shape#[1]

     

     

     

     

     

     

     

     

     

     

    #逆序切片(-x~-1)
    #正序切片(0~x)
    a = tf.range(10)
    print(a[-1:]) #这是9
    print(a[-2:])#8和9
    print(a[:2])#0和1
    print(a[:-1])#[0,1,2,3,4,5,6,7,8]
    #冒号:表示维度都取
    a.shape#([4,28,28,3])
    a[0]#([28,28,3])
    a[0,:,:,:].shape#([28,28,3])
    
    a[:,:,:,0].shape#[4,28,28,1]去R通道
    a[:,:,:,2].shape#[4,28,28,1]取B通道
    
    #start:end:step或者::step(开始:结束:步长)
    a[:,0,:,:].shape#[4,28,3]
    a[:,:14,:14,3].shape#[4,14,14,3]
    a[:,14:,14:,:].shape#[4,14,14,3]
    a[:,::2,::2,:].shape#[4,14,14,3]
    
    a[:,0:28:2,0:28:2,:].shape#[4,14,14,3]
    
    #::实现一个倒序的功能
    a = tf.range(4)#[0,1,2,3]
    a[::-1]#[3,2,1,0]倒序
    a[::-2]#[3,1]
    a[2::-2]#[2,0]
    
    #介绍...三点号的用法
    a = tf.random.normal([2,4,28,28,3])
    
    a[0,:,:,:,:]#[4,28,28,3]
    a[0,...].shape#[4,28,28,3]
    
    a[:,:,:,:,0].shape#[2,4,28,28]
    a[...,0].shape#[2,4,28,28]
    
    a[0,...,2].shape#[4,28,28]
    a[1,0,...,0].shape#[28,28]
  • 相关阅读:
    vue3 el-table多级表头收缩扩展的实现
    整合Shiro+Jwt
    Win10一键重装系统后计算机图标怎么调出来
    统计学习笔记第 1 部分:Hoeffding 的不等式推导与模拟
    使用 qshell 定时备份数据库文件到七牛云并删除7天前的备份(windows版)
    LeetCode刷题(6)
    依赖注入-7
    在小公司编程是一种什么样的体验?
    vscode快捷键分享
    图片怎么识别文字?这几个方法很实用
  • 原文地址:https://blog.csdn.net/chehec2010/article/details/126725781