当前位置:网站首页>Interpret the transfer() function in numpy in detail (with examples to help understand)
Interpret the transfer() function in numpy in detail (with examples to help understand)
2022-07-21 10:32:00 【Width in the journey~】
stay Numpy In transposing a matrix , We can use transpose() Function to handle .
The operation of this function is very counterintuitive , It may lead people to think wrong .
I just feel difficult to understand in the process of learning , Fortunately, I have consulted many materials , Finally, I understand a little .
Two dimensional array
Let's take a look at the two-dimensional array first :
import numpy as np
X=np.arange(6).reshape((2,3))
print(X)
[[0 1 2]
[3 4 5]]
We use transpose() Function to handle :
print(X.transpose())
[[0 3]
[1 4]
[2 5]]
Does the result look familiar ? Yes , Is our usual transpose , It is also very convenient to understand :
transpose() The function is to exchange the index value of the row and column value of the array , Similar to finding the transpose of a matrix .
print(X.T)
[[0 3]
[1 4]
[2 5]]
We can see directly , The row and column index values of the array are swapped ,1 From x(0,1) Run to x(1,0).
Three dimensional array
We continue to generate a three-dimensional array :
x=np.arange(16).reshape((2,2,4))
print(x)
[[[ 0 1 2 3]
[ 4 5 6 7]]
[[ 8 9 10 11]
[12 13 14 15]]]
Our usual idea is
from x Look at the axis ,0, 1 ,2 ,3
from y Look at the axis ,0,4
from z Look at the axis ,0, 8
This expression may be clearer .
The subscripts are arranged as [x, y, z]
in fact , The above axis is wrong , We can test by subscript :
print(x[0,0,0],x[1,0,0])
0 8
But when we continue to change the value of the first index :
print(x[2,0,0])
IndexError: index 2 is out of bounds for axis 0 with size 2
We continue to test :
print(x[0,1,0],x[1,1,0])
4 12
print(x[0,0,1],x[0,0,2])
1 2
It can be seen that , By changing the first subscript , Our actual change is what we usually think z, instead of x,x[1, 0, 0] The number obtained is 8 instead of 1; By changing the third subscript , Our actual change is what we usually think x, instead of z,x[0, 0, 1] The number obtained is 1 instead of 8.
therefore , The subscript of a number is [z, y, x]
transpose Use of functions
First , We make use of transpose Original output :
print(x.transpose((0,1,2))) #z,y,x
[[[ 0 1 2 3]
[ 4 5 6 7]]
[[ 8 9 10 11]
[12 13 14 15]]]
ad locum ,transpose() Functional (0, 1, 2) Corresponding (z, y, x) Axis
When we type in x.transpose((0, 2, 1)) when , Produce the following results :
[[[ 0 4]
[ 1 5]
[ 2 6]
[ 3 7]]
[[ 8 12]
[ 9 13]
[10 14]
[11 15]]]
We can see , When we change 1 and 2 The location of ,x and y Transposed .
When we type in x.transpose((1,0,2)) when , Produce the following results :
[[[ 0 1 2 3]
[ 8 9 10 11]]
[[ 4 5 6 7]
[12 13 14 15]]]
We can see , When we change 1 and 0 The location of ,z and y Transposed .
My understanding is that :x、y、z Can be understood as —— dimension ( Number of channels or superposition of several two-dimensional planes ( high ))—— Rows of two-dimensional matrix —— The number of columns of a two-dimensional matrix .224 The matrix of is 2 individual 2*4 The superposition of the plane matrix of .
summary :
The point is to understand , The subscript of the three-dimensional array is [z, y, x], transpose() The default number for it is 0=z, y=1, x=2.
边栏推荐
猜你喜欢
【Bug解决】VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
Kalman Filter 遇到 Deep Learning : 卡尔曼滤波和深度学习有关的论文
一篇文章快速复习flex属性与用法
出现线上bug,测试人能做些什么?
密集预测任务的多任务学习(Multi-Task Learning)研究综述 - 优化方法篇
Matlab 2021b 安装激活后报错:License Manager Error -103的解决办法
恩智浦i.MX6Q开发板软硬件全开源提供核心板原理图
同时实现射频干扰信号检查与缓解的工作
[neurips 2021] tokenlearner: number and location of adaptive learning tokens - what can 8 learned tokens do for images and videos?
异常,导入包和文件操作
随机推荐
使用es实现个人博客的模糊搜索,搜索推荐
LeetCode 0125. 验证回文串
At the same time, RF interference signal inspection and mitigation are realized
@ModelAttribute运用详解
Generate arbitrary edge smooth shape (patch) artifact
Calculate the rotation matrix between two vectors
剑指Offer 20.表示数值的字符串
[论文速度] 同时解决成像时,曝光不足和曝光过度问题:Deep Reciprocating HDR Transformation
Semantic segmentation-rethinking bisenet for real time semantic segmentation-2-miou calculation
oracle is not null 过滤不了Null值
Four simple operations to realize CPU lightweight network ---- PP lcnet: a lightweight CPU revolutionary neural network
论文速读:FAIR 最新 ViT 模型 改进多尺度 ViT --- Improved Multiscale Vision Transformers
【论文笔记】基于深度强化学习的机器人操作行为研究综述
4.浸泡测试
机器学习—支持向量机理论详细推导(含例题讲解)(三)
2022河南萌新联赛第(二)场:河南理工大学 D - 数对
同时实现射频干扰信号检查与缓解的工作
李宏毅《机器学习》丨4. Deep Learning(深度学习)
服务器内网、外网
log4j配置文件