日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

TensorFlow索引与切片语句

發(fā)布時(shí)間:2025/3/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TensorFlow索引与切片语句 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

學(xué)習(xí)課程
1.Basic indexing

a=tf.ones([1,5,5,3]) #創(chuàng)建tensor a[0][0] #結(jié)果是5*3的tensor a[0][0][0] #結(jié)果是1*3的tensor a[0][0][0][1] #結(jié)果是一個(gè)數(shù)1

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

a[0:2,:,:,:].shape #TensorShape([2,28,28,3]) a[:,0:28:2,:,:].shape #TensorShape([4,14,28,3]) a[:,:14,:,:].shape #TensorShape([4,14,28,3]) a[:,:14,14:,:].shape #TensorShape([4,14,14,3]) a[:,::2,::2,:].shape #TensorShape([4,14,14,3])

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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。