当前位置:网站首页>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 .
边栏推荐
- Biovendor sRAGE antibody solution
- How to design an awesome high concurrency architecture from scratch (recommended Collection)
- Study on modified triphosphate: lumiprobe amino-11-ddutp
- 【JVM】——JVM中内存划分
- How long will the PMP test results come out? You must know this!
- 小球弹弹乐
- OpenSSL client programming: SSL session failure caused by an obscure function
- 拉萨手风琴
- Flink 窗口机制 (两次等待, 最后兜底)
- To batch add background pictures and color changing effects to videos
猜你喜欢

JS中的链表(含leetcode例题)<持续更新~>

Docker installs mysql5.7 and starts binlog

Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid

解决ValueError: Iterable over raw text documents expected, string object received.

Why is point shield cloud forced to quit playing?

Biovendor sRAGE protein solution

Function reentry caused by Keil C51's data overlaying mechanism

如何做好水库大坝安全监测工作

qtcanpool 知 07:Ribbon

How to design an awesome high concurrency architecture from scratch (recommended Collection)
随机推荐
[Linux] - using xshell to install MySQL on Linux and realize the deployment of webapp
Share a powerful tool for factor Mining: genetic programming
When excel copies the contents of a row, the columns are separated by the tab "\t"
mysql 导出查询结果成 excel 文件
[untitled] drv8825 stepping motor drive board schematic diagram
电子邮件营销的优势在哪里?为什么shopline独立站卖家如此重视?
Steve Jobs' speech at Stanford University -- follow your heart
Keil C51的Data Overlaying机制导致的函数重入问题
Line animation
Liuhaiping's mobile phone passes [[uiapplication sharedapplication] delegate] window. safeAreaInsets. The height of the bottom security zone is 0
2022 special operation certificate examination question bank and simulation examination for safety management personnel of fireworks and firecrackers business units
File foundation - read / write, storage
JSP
Shutter nestedscrollview sliding folding head pull-down refresh effect
sklearn 特征工程(总结)
Install kubebuilder
Wedding studio portal applet based on wechat applet
Biovendor sRAGE antibody solution
qtcanpool 知 07:Ribbon
Docker安装Mysql5.7并开启binlog