数组的索引太多 [英] too many indicies for an array

查看:45
本文介绍了数组的索引太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

然后我得到一个错误

Traceback (most recent call last):
  File "c:/Users/Maram/Desktop/Spectrogram/first_attempt.py", line 73, in <module>
    fftArray = fftArray[0:numUniquePoints]
TypeError: slice indices must be integers or None or have an __index__ method 

我不明白这个

或者当我尝试使用稍大的 wav 文件时,它甚至不显示第一张图像.我刚刚收到此错误:

or when i try to use a slightly larger wav file, it doesnt even display the first image. I just get this error:

Traceback (most recent call last):
      File "c:/Users/Maram/Desktop/Spectrogram/first_attempt.py", line 38, in <module>
        mySoundOneChannel = mySound[:,0]
    IndexError: too many indices for array

我认为这些错误在某种程度上是相关的,但我只是不明白它是如何或为什么引起的.

I think these errors are somehow related but i just don't understand how or why it's caused.

有人可以帮我让它运行说一个更大的 wav 文件/更长的轨道,或者帮助我获得我现有的代码来运行功率与频率图?任何帮助将非常感激.

could someone help me get it to run say a larger wav file/longer track, or help me get my existing code to run the power against frequency graph? any help would be really appreciated.

(我不知道这是否被认为是重复的——在最初的问题中,没有人遇到过同样的问题.)

(I dont know if this is considered a duplicate - in the original question no one has the same problems im facing.)

推荐答案

语句 mySoundOneChannel = mySound[:,0] 读取文件的第一个声道.如果您的文件只包含 1 个声道,请将其更改为 mySoundOneChannel = mySound[0:]

The statement mySoundOneChannel = mySound[:,0] reads the first channel of the file. If your file contains only 1 channel change it to mySoundOneChannel = mySound[0:]

至于第二个问题 - numUniquePointsfloat 类型,所以你必须转换它 - numUniquePoints = int(numpy.ceil((mySoundLength + 1)/2.0)) .

As for the second issue - numUniquePoints is of type float, so you must cast it - numUniquePoints = int(numpy.ceil((mySoundLength + 1) / 2.0)).

这篇关于数组的索引太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆