python - 如何附加或连接或合并超过 2 个 numpy 数组?
问题描述
我有 4 个这种形状的 numpy 数组
(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)
(1, 2, 1, 1, 1, 5, 2, 14)
我想将它们合并到一个数组中。形状将是:
(4, 2, 1, 1, 1, 5, 2, 14)
试验 1
np.append(f1, f2, axis=0)
它的形状为(2, 2, 1, 1, 1, 5, 2, 14)
我怎样才能做到这一点?
还是有其他方法来管理这些数据?
我唯一确定的是,4 个阵列的形状相同。
试验 2
np.concatenate(f1, f2, f3)
错误:
----> 1 np.concatenate(f1, f2, f3)
TypeError: only integer scalar arrays can be converted to a scalar index
解决方案
将您的数组放在一个列表中,然后使用np.concatenate
:
import numpy as np
l = [np.ones((1, 2, 1, 1, 1, 5, 2, 14))] * 4
a = np.concatenate(l, axis=0)
a.shape
Out[9]: (4, 2, 1, 1, 1, 5, 2, 14)
推荐阅读
- c# - Get the minimum and second minimum of this array
- node.js - 如何从 Azure 函数内部发出基于承诺的 HTTP 发布请求 (NodeJS)?
- android - 如何使用带有 angular2 和 nativescript 的会话 cookie 支持自动登录
- angular - 为什么 Angular 组件未在浏览器后退/前进导航上加载?
- android - App doesn't install on the emulator and stuck on "Waiting for target device to come online"
- python - 为什么一个线程无法检测到另一个线程更新的更改值?
- c++ - C ++防止浮点寄存器在页面错误处理程序中归零
- html - background-size not working. How do I fix the obvious?
- verilog - Verilog 高阻抗输入输出合成
- tensorflow - How to properly perform data-augmentation on MRI and prepare them for deep learning?