我正在从音频剪辑中提取特征。在为 1 个剪辑执行此操作时,20x2将获得一个维度矩阵。我有1000很多这样的剪辑。我想将所有数据存储在 1 个 numpy 维度数组中20x2x1000。请提出相同的方法。
2 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
您正在寻找的功能是np.stack. 它用于沿新轴堆叠多个 NumPy 数组。
import numpy as np
# Generate 1000 features
original_features = [np.random.rand(20, 2) for i in range(1000)]
# Stack them into one array
stacked_features = np.stack(original_features, axis=2)
assert stacked_features.shape == (20, 2, 1000)
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
有一个方便的函数,那就是numpy.dstack。下面是数组深度堆叠的代码片段:
# whatever the number of arrays that you have
In [4]: tuple_of_arrs = tuple(np.random.randn(20, 2) for _ in range(10))
# stack each of the arrays along third axis
In [7]: depth_stacked = np.dstack(tuple_of_arrs)
In [8]: depth_stacked.shape
Out[8]: (20, 2, 10)
添加回答
举报
0/150
提交
取消