我有光谱图。它是129行x n列。 我想把柱子“剪”成20根。我会这样做:
if spectrogram.shape[1] > 20:
for row in spectrogram:
i = spectrogram.index(row)
row = row[:20]
spectrogram[i] = row
但是它抛出了一个使用.index()
的错误,所以我尝试使用.where()
,正如我在SOF上看到的那样,但是出现了另一个错误:
AttributeError: 'numpy.ndarray' object has no attribute 'where'
我该怎么办?你知道吗
您应该能够在没有循环的情况下获取所需的切片(每当您试图在numpy数组上循环时,通常有更好的方法)。你知道吗
下面是一个简化的示例:给定一个5x10数组,只取每行的前5个,就得到一个5x5数组:
结果
相关问题 更多 >
编程相关推荐