当前位置:网站首页>numpy. reshape, numpy. Understanding of transfer
numpy. reshape, numpy. Understanding of transfer
2022-06-28 05:35:00 【Cool wardrobe】
These two commands are often used when changing the matrix , After a long time, I will return to think about their influence on the result of matrix transformation . Here is an example of :
1.np.reshape
This command rearranges the matrix elements , See the code :
a = np.random.randint(1, 10, [1, 6, 2] )
print(a)
print(a.reshape(2, 3, 2))
print(a.reshape(3, 2, 2))
print(a.reshape(3, 2, 2).transpose(1, 0, 2))
The result is :
#print(a)
[[[9 1]
[5 8]
[4 2]
[7 1]
[4 9]
[7 9]]]
#print(a.reshape(2, 3, 2))
[[[9 1]
[5 8]
[4 2]]
[[7 1]
[4 9]
[7 9]]]
#print(a.reshape(3, 2, 2))
[[[9 1]
[5 8]]
[[4 2]
[7 1]]
[[4 9]
[7 9]]]
#print(a.reshape(3, 2, 2).transpose(1, 0, 2))
[[[9 1]
[4 2]
[4 9]]
[[5 8]
[7 1]
[7 9]]]
reshape After that, the original matrix is actually rearranged . Also found here a.reshape(2, 3, 2).reshape(3, 2, 2) And .reshape(3, 2, 2) Consistent result . Here np.transpose Put it in the 2 In the section .
2.np.transpose
This function is used to realize the transpose of matrix . For high-dimensional matrix, this function can also realize dimension exchange , But with reshape Dissimilarity . Here is the transposed exchange dimension , The order of arrangement will not be the same as the original . Let's start with a two-dimensional matrix :
mm = np.random.randint(1, 10, [2, 3])
print(mm)#[[1 3 3]
#[9 3 8]]
print(mm.transpose(1, 0))#[[1 9]
#[3 3]
#[3 8]]
Here is the transposed exchange dimension . This can be understood again 1 Section a.reshape(3, 2, 2).transpose(1, 0, 2). Transpose occurs only in 0 and 1 In dimension ,2 Dimensions can be viewed as fixed elements . The result shows that ,transpose Yes, it will 0 and 1 Dimension transpose , also ,a.reshape(3, 2, 2).transpose(1, 0, 2) And a.reshape(2, 3, 2) The result is different , The former is based on transpose to change the dimension , The latter still assembles elements from front to back , Pay special attention to .
边栏推荐
- Zzuli:1072 frog climbing well
- 数据中台:六问数据中台
- 证明素数/质数有无限多个
- Linked list in JS (including leetcode examples) < continuous update ~>
- jsp连接oracle实现登录注册(简单)
- Biovendor sRAGE antibody solution
- 数据中台:AI中台的实施与总结
- Study on modified triphosphate: lumiprobe amino-11-ddutp
- Concurrent wait/notify description
- FB、WhatsApp群发消息在2022年到底有多热门?
猜你喜欢

gorm事务体验

Store inventory management system source code
![[CAD drawing Video] AutoCAD 2014 master's way](/img/19/7013333c028d7db02e356661b9ffc3.jpg)
[CAD drawing Video] AutoCAD 2014 master's way

How to learn programmable logic controller (PLC)?

To batch add background pictures and color changing effects to videos

北斗三号短报文终端在大坝安全监测方案的应用

Study on modified triphosphate: lumiprobe amino-11-ddutp

【JVM】——JVM中内存划分

Oracle 条件、循环语句

Create NFS based storageclass on kubernetes
随机推荐
2022 new version NFT source code source code of China meta universe digital collection art trading platform
MySQL 45 talk | 05 explain the index in simple terms (Part 2)
How to do a good job of dam safety monitoring
How does the power outlet transmit electricity? Simple problems that have plagued my little friend for so many years
Why don't big manufacturers use undefined
[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer
Reactive dye research: lumiprobe af594 NHS ester, 5-isomer
Typescript base type
WordPress zibll sub theme 6.4.1 happy version is free of authorization
JSP connecting Oracle to realize login and registration
CpG solid support research: lumiprobe general CpG type II
FB、WhatsApp群发消息在2022年到底有多热门?
中小型水库大坝安全自动监测系统解决方案
【JVM】——JVM中内存划分
[JVM] - Division de la mémoire en JVM
Why does the company choose cloud database? What is its charm!
【C语言练习——打印空心正方形及其变形】
Line animation
数据中台:AI中台的实施与总结
Question bank and answers of 2022 materialman general basic (materialman) operation certificate examination