【发布时间】:2020-02-29 18:24:42
【问题描述】:
我有一个形状为 (40, 926) 的多维 numpy 数组。 我还有一个 numpy 数组形状 (126),其中包含表示有效列的随机索引。
现在,我想做的是根据这个索引掩码过滤我的多维数组:必须删除与这个索引不同的所有列,结果形状 (40,126)
所以,类似:
data = np.array([[]])
sel = np.asarray(idx.split(','))
print sel.shape #(126) array 404,410,500...1300
print X.shape #(40,926)
for x in wave: #(926) array 400,401,402...1325
for y in sel:
if float(x) == float(y):
index = np.where(wave == x)[0][0]
arr = X[:,index]
data = np.append(data, arr, axis=1)
print data.shape #must be (40,126)
return data
发生错误:返回连接((arr,值),轴=轴) ValueError: 所有输入数组的维数必须相同
【问题讨论】: