1 回答

TA贡献1815条经验 获得超13个赞
由于您的MEL数组不是均匀形状,首先我们需要过滤掉形状常见的数组(即(99, 13))。为此,我们可以使用:
filtered = []
for arr in MEL:
if arr.shape == (99, 13):
filtered.append(arr)
else:
continue
然后我们可以初始化一个数组来保存结果。然后我们可以迭代这个过滤后的数组列表并计算轴 1 上的平均值,如:
averaged_arr = np.zeros((len(filtered), 99))
for idx, arr in enumerate(filtered):
averaged_arr[idx] = np.mean(arr, axis=1)
这应该计算所需的矩阵。
这是一个重现您的设置的演示,假设所有数组都具有相同的形状:
# inputs
In [20]: MEL = np.empty(94824, dtype=np.object)
In [21]: for idx in range(94824):
...: MEL[idx] = np.random.randn(99, 13)
# shape of the array of arrays
In [13]: MEL.shape
Out[13]: (94824,)
# shape of each array
In [15]: MEL[0].shape
Out[15]: (99, 13)
# to hold results
In [17]: averaged_arr = np.zeros((94824, 99))
# compute average
In [18]: for idx, arr in enumerate(MEL):
...: averaged_arr[idx] = np.mean(arr, axis=1)
# check the shape of resultant array
In [19]: averaged_arr.shape
Out[19]: (94824, 99)
添加回答
举报