当前位置:网站首页>数组拼接时维度的重要性
数组拼接时维度的重要性
2022-08-08 06:20:00 【波尔德】
axis参数为指定按照哪个维度进行拼接。
下面的例子中:x1为[5,4], x2为[3,4],设置axis=0则代表着按照第一维度(按行)进行拼接,拼接后的尺寸为[8,4]。可以看到,除了第一维度的尺寸发生变化(5+3=8)外,其他维度不变。
同时也说明,必须保证其他维度的尺寸是能对的上的,如果x1为[5,4],x2为[5,3],如果设置axis=1的话,则会报错,因为x1和x2的第二维度尺寸不相等,无法拼接。
按照axis=0(按行拼接)实例如下:
import numpy as np
x1 = np.random.normal(1,1,(5,4))
x2 = np.random.normal(1,1,(3,4))
print(x1)
print(x1.shape)
print(x2)
print(x2.shape)
con = np.concatenate([x1,x2],axis=0)
print(con)
print(con.shape)
输出结果为:
[[ 2.22806658 0.15277615 2.21245262 1.63831116]
[ 1.30131232 -1.09226289 -0.65959394 1.16066688]
[ 1.52737722 0.84587186 1.53041503 0.4584277 ]
[ 1.56096219 1.29506244 3.08048523 2.06008988]
[ 1.79964236 0.95087117 1.30845477 -0.2644263 ]]
(5, 4)
[[0.89383392 1.49502055 2.90571116 1.71943997]
[1.44451535 1.87838383 1.4763242 0.82597179]
[0.72629108 1.42406398 1.35519112 0.58121617]]
(3, 4)
[[ 2.22806658 0.15277615 2.21245262 1.63831116]
[ 1.30131232 -1.09226289 -0.65959394 1.16066688]
[ 1.52737722 0.84587186 1.53041503 0.4584277 ]
[ 1.56096219 1.29506244 3.08048523 2.06008988]
[ 1.79964236 0.95087117 1.30845477 -0.2644263 ]
[ 0.89383392 1.49502055 2.90571116 1.71943997]
[ 1.44451535 1.87838383 1.4763242 0.82597179]
[ 0.72629108 1.42406398 1.35519112 0.58121617]]
(8, 4)
按照axis=1(按列拼接)的维度进行拼接,实例如下:
import numpy as np
x1 = np.random.normal(1,1,(5,4))
x2 = np.random.normal(1,1,(5,2))
print(x1)
print(x1.shape)
print(x2)
print(x2.shape)
con = np.concatenate([x1,x2],axis=1)
print(con)
print(con.shape)
输出结果如下:
[[ 1.06700795 2.49432822 0.13721596 0.86647501]
[-0.24454185 0.83414428 2.06012125 -0.63322426]
[ 2.01993142 -0.27599932 1.9101389 1.92564214]
[ 0.12627442 0.97560762 2.00993226 2.02754602]
[ 0.23883256 1.4805339 -0.83029287 1.37207756]]
(5, 4)
[[ 0.67988459 2.46464482]
[ 1.19166015 2.16522311]
[ 1.41193468 -0.01165058]
[ 0.62496307 1.05706225]
[ 0.85055712 -0.09588572]]
(5, 2)
[[ 1.06700795 2.49432822 0.13721596 0.86647501 0.67988459 2.46464482]
[-0.24454185 0.83414428 2.06012125 -0.63322426 1.19166015 2.16522311]
[ 2.01993142 -0.27599932 1.9101389 1.92564214 1.41193468 -0.01165058]
[ 0.12627442 0.97560762 2.00993226 2.02754602 0.62496307 1.05706225]
[ 0.23883256 1.4805339 -0.83029287 1.37207756 0.85055712 -0.09588572]]
(5, 6)
边栏推荐
- 网络安全:系统文件属性
- 验证的计划
- Redis In Action —— Advanced —— 数据主从同步原理 —— 全量同步 与 增量同步 工作流程及原理 —— 以及如何利用 docker 容器技术快速模拟单机 Redis 集群
- [u-boot] Analysis of the driver model of u-boot
- 【MySQL】——事务的基本概念
- don't know what to name
- postgres 安装 14 版本出现错误提示解决办法
- Runtime——KVC,KVO原理
- Graphical LeetCode - 636. Exclusive Time of Functions (Difficulty: Moderate)
- State Compression Review
猜你喜欢

缓存存在的问题:缓存穿透、缓存击穿、缓存雪崩

don't know what to name

The tests that need to be done in the development of medical device products

APISIX Ingress v1.5-rc1 released

APISIX Ingress v1.5-rc1 发布

docker修改mysql配置文件

Typescript namespace

torch.gather() 用法解读

Several postman features worth collecting will help you do more with less!

七千字带你了解封装等机制
随机推荐
Redis In Action —— Advanced —— 数据主从同步原理 —— 全量同步 与 增量同步 工作流程及原理 —— 以及如何利用 docker 容器技术快速模拟单机 Redis 集群
【u-boot】u-boot的驱动模型分析
Rust development - Struct usage example
Runtime - KVC, KVO principle
The CAP theorem instance analysis
How to batch import files and rename them all to the same file name
打开deploy和manager图形化界面打不开
卷积神经网络的基本操作,卷积神经网络卷积计算
线上接口流量突增,快要扛不住了
How many times the neural network is generally trained, the neural network training time is too long
仿记事本;QFile
主脑提示( Master-Mind Hints )
CAP定理实例分析
四面拿下字节2-2Offer,入职就是...
字符串哈希 哈希值
“独家全新”MySQL进阶套餐,你确定不看吗?
MySQL5
探索数字安全中国方案
Graphical LeetCode - 636. Exclusive Time of Functions (Difficulty: Moderate)
LLVM系列第二十九章:写一个简单的常量加法“消除”工具(Pass)