当前位置:网站首页>Numpy on the superposition of two arrays
Numpy on the superposition of two arrays
2022-08-04 21:50:00 【Shocked】
numpyThere's a lot about botharray的操作,How they stack up and what dimensions they stack up to are often confusing,The total price of this article.
一、 Overlay operation
- add
逐元素操作,若是array + 常量
broadcast to every element,若是array + array
two are requiredarray
的shape
一致.
end = '\n'+'*'*50+'\n'
a = np.array([[1,2],[3,4]])
b = np.array([[5,6], [7,8]])
print(a+1, end=end)
print(a+b)
输出:
[[2 3]
[4 5]]
**************************************************
[[ 6 8]
[10 12]]
- concatenate
Put two in the specified dimensionarray进行拼接,不会改变array的维度,要求两个array的维度相同,And in the specified splice dimensionarray size也必须相等,值得注意的是,两个array的shape不一定一致,比较拗口,看下例子:
end = '\n'+'*'*50+'\n'
a = np.array([[1,2],[3,4]])
b = np.array([[5,6], [7,8]])
c = np.array([[5,6]])
d = np.array([5,6])
f = np.array([[5]])
a & c 的shape并不相同:
维度不一致:长度不一致:
- stack & hstack
stack Splicing two verticallyarray(可以指定axis),要求两个array的shape严格一致,The result adds dimension;
hstack 在水平方向(第0维,Not availableaxis)拼接两个array,The dimensions of both are required to be the same,且在第0维的size也相同,The stitching result does not change the original dimension .
stack:The result will be added to the original dimension1
hstack,a和c在0轴的size不同:hstack,Normal stitching after transposition:
二、 size & ndim & shape
These three concepts are easily confused,其中:size
:指的是“元素个数”;ndim
:维度,指的是“How many levels of nesting there are”,That is, the number of square brackets,同时和shape的len相等,axis=0Refers to the outermost square brackets,Incrementally inward;shape
:size和ndim综合起来就是shape,两个array的shapeSame means bothndimthe same and in every oneaxis上的size也相同.
看下例子:
值得注意的是,ndim和size以及shape没有必然联系,一个ndim不为0的arrayPossibly none of the elements:
size相同,shape和ndim也不一定相同:
边栏推荐
- 信创是什么意思?涉及哪些行业?为什么要发展信创?
- 经验分享|盘点企业进行知识管理时的困惑类型
- 搬走地下空间开发利用“绊脚石” 中地数码取得地下空间透明化技术突破
- 【CC3200AI 实验教程 1】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-开发环境搭建
- 数电快速入门(三)(卡诺图化简法的介绍)
- Named routes, the role of name in components
- Is the International Project Manager PMP certificate worth taking?
- Why is MySQL query slow?
- 快速web开发框架——learun framework
- AXI interface application of Zynq Fpga image processing - the use of axi_lite interface
猜你喜欢
基于 Milvus 和 ResNet50 的图像搜索(部署及应用)
PowerCLi batch configuration of NTP
如何为Web3.0世界启动完美的DAO
打卡第 1 天:正则表达式学习总结
Is the International Project Manager PMP certificate worth taking?
Axure9基本交互操作(一)
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd6 in position 120: invalid continuation byte
数电快速入门(二)(复合逻辑运算和逻辑代数的基本定律的介绍)
MySQL查询为啥慢了?
数电快速入门(一)(BCD码和三种基本逻辑运算的介绍)
随机推荐
ES6高级-async的用法
未知点云结构文件转换需求
y87.第五章 分布式链路追踪系统 -- 分布式链路追踪系统起源(一)
【CC3200AI 实验教程 1】疯壳·AI语音人脸识别(会议记录仪/人脸打卡机)-开发环境搭建
PowerBI真经连续剧
docker 部署redis集群
How to solve the problem that the alarm information cannot be transmitted after EasyGBS is connected to the latest version of Hikvision camera?
热力学相关的两个定律
CPU、内存、显卡等硬件因素也影响着你的深度学习模型性能
mysql基础
JWT actively checks whether the Token has expired
rk3399-9.0一级二级休眠
Pinduoduo open platform order information query interface [pdd.order.basic.list.get order basic information list query interface (according to transaction time)] code docking tutorial
OD-Model [6]: YOLOv2
如何一键重装Win11系统 一键重装系统方法
数电快速入门(四)(组合逻辑电路的分析以及设计的介绍)
LeetCode: 406. 根据身高重建队列
Why is MySQL query slow?
1.读写点云文件
Autowired自动装配