当前位置:网站首页>Learning about tensor (III)
Learning about tensor (III)
2022-07-26 10:11:00 【SingleDog_ seven】
Index and slice
Index method :
The first one is : The most basic indexing method , The second kind : use : Go to index , The third kind of : use ... Go to index .( I don't know if it's right )
First, let's talk about the first :
a = tf.ones([1,5,5,3])
print(a[0])
print(a[0][0])
print(a[0][0][0]) # The most basic indexing method , Give the value of each layer Give the value of each layer .
The second kind :
b = tf.random.normal([4,28,28,3])
print(b[1].shape)
print(b[1,2].shape) # =b[1][2]
c=tf.range(10)# Use positive numbers near the initial segment , End with a negative number
print(c[-1:])# c[a:b] from a Fetch b( It doesn't contain b), Don't write b Words represent from a To the end , Don't write a The words represent from the initial paragraph to b
# Don't write = Default
# Take a piece of data
#a[0].shape = a[0,:,:,:]
print(a[:,:,:,0].shape) # Take the middle dimension
print(a[:,0,:,:].shape)
# Add one more : Take across
#a[::3] Take one data every three
print(a[:,0::4,:,:]) # Take it every four points
print(a[::-1]) # flashback
print(a[::-2]) # Take across Based on the first one, the simplified operation is carried out , And achieve data retrieval across fixed data .
notes :c[a:b] from a Fetch b( It doesn't contain b), Don't write b Words represent from a To the end , Don't write a The words represent from the initial paragraph to b
The third kind of : Simplify the operation based on the second :
# ... # Automatic derivation
# Instead of consecutive colons
print(a[...,0]) #0 Represents the last dimension
print(a[:,:,:,0])Slicing :
#Selective indexing
utilize gather Slice it .
#Selective indexing
#gather collect
# Specify the number of lines
d = tf.random.normal([4,35,8])
print(tf.gather(a,axis=0,indices=[2,3]))
#axis Which dimension does it represent indices Which index does it represent
# Can be used in combination with (axis=) Represents the dimension ,indices= It represents the index
print(tf.gather_nd(d,[0]).shape)
# As d[0]
print(tf.gather_nd(d,[[[0,0,0],[1,1,1],[2,2,2]]]))
print(tf.gather_nd(d,[[0,0,0],[1,1,1],[2,2,2]]))

With one bracket and two brackets shape Will change .
utilize boolean_mask Slice it .
a=tf.random.normal([4,28,28,3])
print(tf.boolean_mask(a,mask=[True,True,False,False]).shape)
print(tf.boolean_mask(a,mask=[True,True,False],axis=3).shape)
# Not specified axis The default is 0 
Note that... Is not specified axis The default is 0.
a = tf.ones([2,3,4])
print(tf.boolean_mask(a,mask=[[True,False,False],[False,True,True]])) 
Slice the corresponding dimension according to the brackets in brackets . 
边栏推荐
- What is the principle of reflection mechanism?
- Apple dominates, Samsung revives, and domestic mobile phones fail in the high-end market
- 论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
- All codes of Tetris
- Nodejs service background execution (forever)
- Study notes at the end of summer vacation
- Spolicy request case
- Mysql5.7.25 master-slave replication (one-way)
- SQL优化的魅力!从 30248s 到 0.001s
- 2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
猜你喜欢

点赞,《新程序员》电子书限时免费领啦!

Principle analysis and source code interpretation of service discovery

Uniapp "no mobile phone or simulator detected, please try again later" and uniapp custom components and communication

Flask框架初学-04-flask蓝图及代码抽离
![Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da

Applet record

Mysql5.7.25 master-slave replication (one-way)
![Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res](/img/8e/265af6b20f79b21c3eadcd70cfbdf7.png)
Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res

30 minutes to thoroughly understand the synchronized lock upgrade process

The diagram of user login verification process is well written!
随机推荐
MySQL 5.7.25 source code installation record
Basics of data communication - basic knowledge of network
Flutter event distribution
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken
Meeting OA project (III) -- my meeting (meeting seating and submission for approval)
新建福厦铁路全线贯通 这将给福建沿海带来什么?
30 minutes to thoroughly understand the synchronized lock upgrade process
Data communication foundation TCPIP reference model
regular expression
protobuf的基本用法
On the compilation of student management system of C language course (simple version)
Production of a-modal drag function in antui
Common errors when starting projects in uniapp ---appid
挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
PMM (percona monitoring and management) installation record
WARNING: [pool www] server reached pm. max_ children setting (5), consider raising it
SSG框架Gatsby访问数据库,并显示到页面上
Usage of the formatter attribute of El table
Write a script that can run in Bash / shell and PowerShell