TensorFlow索引与切片语句
生活随笔
收集整理的這篇文章主要介紹了
TensorFlow索引与切片语句
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
學(xué)習(xí)課程
1.Basic indexing
2.Numpy-style indexing
a = tf.random.normal([4,28,28,3]) #4張照片 a[1].shape #第2張照片的信息維度,TensorShape([28,28,3]) a[1,2].shape #第二張照片第三行的信息維度,TensorShape([28,3]) a[1,2,3].shape #第二張照片第三行第四列的信息維度TensorShape([3]) a[1,2,3,2].shape #第二張照片第三行第四列地三層的信息維度TensorShape([])3.start:end #左閉右開(kāi)
a=tf.range(10) a[-1:] #結(jié)果為[9] a[-2:] #結(jié)果為[8,9] a[1:] #結(jié)果為[1,2,3,4,5,6,7,8,9] a[:-1] #結(jié)果為[0,1,2,3,4,5,6,7,8]4.Indexing by :
a = tf.random.normal([4,28,28,3]) #4張照片 a[0].shape #第1張照片的信息維度,TensorShape([28,28,3]) a[0,:,:,:].shape #第1張照片的信息維度,TensorShape([28,28,3]) a[0,1,:,:].shape #第1張照片第1行的信息維度,TensorShape([28,3]) a[:,:,:,2].shape #第三層信息維度,TensorShape([4,28,28]) a[:,0,:,:].shape #第1行信息維度,TensorShape([4,28,3])5.Indexing by ::
start: end:step
::step
6.::-1 #逆序
a=tf.range(4) #[0,1,2,3] a[::-1] #[3,2,1,0] a[::-2] #[3,1] a[2::-2] #[2,0]7.…
a = tf.random.normal([2,4,28,28,3]) #,2個(gè)tasts,4張照片 a[0].shape #TensorShape([4,28,28,3]) a[0,:,:,:,:].shape #TensorShape([4,28,28,3]) a[0,...].shape #TensorShape([4,28,28,3]) a[:,:,:,:,0].shape #TensorShape([2,4,28,28]) a[...,0].shape #TensorShape([2,4,28,28]) a[0,:,:,:,0].shape #TensorShape([4,28,28]) a[0,...,0].shape #TensorShape([4,28,28])8.tf.gather
a=tf.random.normal([4,35,8]) #4個(gè)班級(jí),每個(gè)班級(jí)35個(gè)學(xué)生,每個(gè)學(xué)生8科課程 tf.gather(a,axis=0,indices[2,3]).shape #TensorShape([2,35,8]),選第3和第4個(gè)班級(jí)的所有數(shù)據(jù) a[2:4].shape #TensorShape([2,35,8]),選第3和第4個(gè)班級(jí)的所有數(shù)據(jù) tf.gather(a,axis=0,indices[3,2,4,1]).shape #TensorShape([4,35,8]),所有班級(jí)所有數(shù)據(jù),但班級(jí)查看順序不一樣 tf.gather(a,axis=1,indices[2,4,7]).shape #TensorShape([4,3,8]),所有班級(jí)的第3,5,8號(hào)學(xué)生的所有科目成績(jī)9.tf.gather_nd
略
10.tf.boolean_mask
略
總結(jié)
以上是生活随笔為你收集整理的TensorFlow索引与切片语句的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: TensorFlow创建tensor语句
- 下一篇: TensorFlow维度变换函数语句