当前位置:网站首页>np.transpose & np.expand_dims
np.transpose & np.expand_dims
2022-07-26 22:21:00 【Fire丶Chicken】
np.transpose & np.expand_dims
一、numpy.transpose(a, axes=None)
功能:
对高维数组进行坐标轴上的变换,即进行转置操作。
参数:
a: Numpy输入数组
axes: 如果指定,它必须是包含 [0,1,…,N-1] 排列的元组或列表,其中 N 是 a 的轴数(可以理解为维度)。返回数组的第 i 个轴将对应于axes[i]输入的编号轴。如果未指定,则默认为range(a.ndim)[::-1],这会反转轴的顺序
返回:
dst: 转置后的数组
用线性代数的来表达的话跟下图一样:

说得简单点transpose()的功能就是改变数组中不同维度的位置。
举个例子:
import numpy as np
x = np.ones((1,2,3)) #我们先创建一个三维的数组

我们使用 transpose() 函数交换 x 数组不同维度的位置:
x_temp = np.transpose(x, (1, 0, 2))

很明显,我们可以看到x数组的第0维和第2维交换位置,原本是(1,2,3)格式的数组变成了(2,1,3)格式。
二、numpy.expand_dims(a, axes=None)
功能:
对数组新添加一个维度
参数:
a: Numpy输入数组
axes: 放置新维度(或多个维度)的位置。
返回:
dst: 添加新维度后的数组
例子:
x = np.ones((1,2,3))
x_temp2 = np.expand_dims(x,0) #在0维度插入一个新的维度

x = np.ones((1,2,3))
x_temp2 = np.expand_dims(x,axis=(0, 1)) #axis也可能是一个元组

边栏推荐
- Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
- Dynamic memory management and related topics
- 关于 StatefulWidget,你不得不知道的原理和要点!
- Esmfold: a new breakthrough in protein structure prediction after alphafold2
- Cloud native microservices Chapter 1 server environment description
- Practical project: boost search engine
- Real time voice quality monitoring
- Day07 MySQL knowledge points re summary and multi table query
- [Luogu] p2341 popular cattle
- Novice online interview [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
猜你喜欢

Introduction to the use of Jerry downloader forced download tool_ Ac695n696nad14ad15 full range support

App information reconnaissance & night God simulator burp packet capture configuration

Too busy with scientific research to take care of your family? Chen Ting: life cannot have only one fulcrum

PostgreSQL and Navicat: the backbone of the database industry

逆袭黑马:数据库全栈工程师(DevDBOps)培训,把最好的课程送给您!

HCIA-R&S自用笔记(23)DHCP

你知道磁环电感的常见磁芯类型有哪些吗?

Basic use of gateway

Vit:vision transformer super detailed with code

HCIA-R&S自用笔记(19)VLAN配置及实验、VLAN间路由
随机推荐
程序员成长第二十九篇:如何激励员工?
The most classic Nature paper on Alzheimer's disease is suspected of fraud
Eureka basic use
App information reconnaissance & night God simulator burp packet capture configuration
[shader realizes shine effect _shader effect Chapter 3]
Distributed lock and its implementation
How to recover the original data when the U disk is damaged, and how to recover the damaged data when the U disk is damaged
Disk expansion process and problems encountered in the virtual machine created by VMWare
HCIA-R&S自用笔记(21)STP技术背景、STP基础和数据包结构、STP选举规则及案例
Xinding acquires Ziguang holdings! Wanye enterprise: comprehensive transformation of integrated circuits!
Six challenges facing enterprise data governance!
Is test development development development?
Reinforcement learning weekly 55: lb-sgd, msp-drl & robust reinforcement learning against
How to use data pipeline to realize test modernization
gateway基本使用
After working for one year, I have some insights (written in 2017)
[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version
8 other programming languages -- Recording
Three person management of system design
逆袭黑马:数据库全栈工程师(DevDBOps)培训,把最好的课程送给您!