当前位置:网站首页>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 + arraytwo 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也不一定相同:
边栏推荐
- 【社媒营销】WhatsApp Business API:您需要知道的一切
- In action: 10 ways to implement delayed tasks, with code!
- [Linear Algebra 02] 2 interpretations of AX=b and 5 perspectives of matrix multiplication
- 如何将二叉搜索树转化为一个有序的双向链表(原树上修改)
- 看看XDOC如何做Word文档预览
- 七夕特制:《牛郎会织女》
- ES6高级-Promise的用法
- NFT宝典:你需要知道NFT的术语和定义
- ue unreal 虚幻 高分辨率无缩放 编辑器字太小 调整编辑器整体缩放
- OC-协议
猜你喜欢

【Social Marketing】WhatsApp Business API: Everything You Need to Know

Qiangwang Cup 2022 - WEB

AXI interface application of Zynq Fpga image processing - the use of axi_lite interface

PowerCLi import license to vCenter 7

七夕特制:《牛郎会织女》

NFT宝典:你需要知道NFT的术语和定义

PyTorch Geometric (PyG) 安装教程

Axure9基本交互操作(一)

buu web

In action: 10 ways to implement delayed tasks, with code!
随机推荐
EasyGBS接入最新版海康摄像头后无法传递告警信息该如何解决?
stm32mp157系统移植 | 移植ST官方5.10内核到小熊派开发板
Is the International Project Manager PMP certificate worth taking?
【PCBA program design】Grip dynamometer program
Why is MySQL query slow?
JWT actively checks whether the Token has expired
boostrap多选PID查找端口 window
Red team kill-free development practice of simulated confrontation
Exploration and Practice of Database Governance
热力学相关的两个定律
VSCode—常用快捷键(持续记录
信创是什么意思?涉及哪些行业?为什么要发展信创?
com.jacob.com.ComFailException: Invoke of: ActiveDocument
Hardware factors such as CPU, memory, and graphics card also affect the performance of your deep learning model
[larave]关于laravel使用form submit()不能获取值问题
8 年产品经验,我总结了这些持续高效研发实践经验 · 协同篇
LeetCode143:重排链表
SPSS-unary regression practice
In action: 10 ways to implement delayed tasks, with code!
OC-归档(序列化)(了解的不多 没细看)