当前位置:网站首页>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也不一定相同:
边栏推荐
- PMP证书在哪些行业有用?
- 论文解读(PPNP)《Predict then Propagate: Graph Neural Networks meet Personalized PageRank》
- 基于声卡实现的音频存储示波器,可作为电磁学实验的测量仪表
- Flutter 实现背景图片毛玻璃效果
- Cocoa Application-基础
- Cocoa Application-test
- buu web
- js data type, throttling/anti-shake, click event delegation optimization, transition animation
- Named routes, the role of name in components
- OC-归档(序列化)(了解的不多 没细看)
猜你喜欢
随机推荐
Altium Designer 19.1.18 - draw polygons copper hollow out, for the cursor just capture solutions
如何一键重装Win11系统 一键重装系统方法
【SQL之降龙十八掌】01——亢龙有悔:入门10题
《剑指offer》刷题分类
Red team kill-free development practice of simulated confrontation
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
1.读写点云文件
Three ways to set a specific device UWP XAML view
【uiautomation】微信好友列表获取(存储到txt中)
Moke, dynamic image resource package display
milvus配置相关
LayaBox---TypeScript---Example
Analysis and treatment of Ramnit infectious virus
快速web开发框架——learun framework
Oracle增加表空间解决ORACLE ORA-01653: unable to extend table报错
搬走地下空间开发利用“绊脚石” 中地数码取得地下空间透明化技术突破
Hands-on Deep Learning_NiN
ROS播包可视化
AI/ML无线通信
如何为Web3.0世界启动完美的DAO









