• 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]
  • 相关阅读:
    html计算器
    String 常用方法
    【vsCode + Arduino】在Visual Studio Code编译Arduino项目
    医院智能电力系统解决方案
    位运算的应用--->位图
    阿里云对象存储OSS SDK的使用
    基于Streamlit的YOLOv5ToX模型转换工具(适用YOLOv5训练出来的模型转化为任何格式)
    惨败阿里,洒泪复习3个月!上岸美团惨遭面试官狂问MySQL
    JAVA集合(一)Collection接口
    C++(17):模板嵌套类的.template及::template
  • 原文地址:https://blog.csdn.net/chehec2010/article/details/126725781