tensorflow支持下标取值和切片,类似numpy的风格,详细可见代码以及其中的注释。
# coding: utf-8
# @时间 : 2022/3/26 14:58
# @作者 : 那美那美 v: qwentest123
import tensorflow as tf
from datetime import datetime
def pprint(*args,**kwargs):
print(datetime.now(),*args,**kwargs,end='\n'+'*'*50+'\n')
print('# 基本下标操作')
a = tf.ones([1,5,5,3])#[1bitch,5width,5size,3chanels]
pprint(a)#shape(1,5,5,3) 切片的取值方法tesor[index][index][index]
pprint(a[0][0])#shape(5,3)
pprint(a[0][0][0])#shape(3,)
pprint(a[0][0][0][2])#shape(3,),second
#**************************************************
print('# 类似numpy的下标取值的操作')
a = tf.random.normal([4,28,28,3])#[4bitch,28width,28size,3chanels]
pprint(a)
pprint(a[0].shape)#[28,28,3] 由外向内
pprint(a[0,2].shape)#[28,3]
p
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



