试图循环numpy数组python

时间:2014-05-05 12:03:02

标签: python arrays numpy

我正在尝试打开文本文档并将数据放入数组中。这很好,但是当我试图循环遍历数组并搜索array[][2] is >=1超过100个样本的位置时代码失败。我之前从未使用过numpy,但是脚本必须搜索的数据量可能在Rasberry Pi上达到一百万行数据,所以我必须写一些快速的东西。

#reads the log data into a array
data = np.genfromtxt(('tilfeldigetall.txt'),dtype= 'float', delimiter="")
for i in np.nditer(data, flags=['external_loop']):
    # checks if the Z axis has been stable for more then 100 samples. 
    if all(data[i][2] >= 1 for a in np.nditer(100, flags=['external_loop'])):
          # Gathers the data from when it's stable and 10 sec back in time
          for n in reversed(2700):
                    Ax = data[i-n][0]
                    Ay = data[i-n][1]
                    Az = data[i-n][2]
                    #calculate angle from acc
                    delta = (Az/sqrt(((Ax*Ax)+(Ay*Ay)+(Az*Az))))
                    AanchorAngle = math.atan(delta)
                    AanchorAngle =math.degrees(AanchorAngle)
                    AanchorAngle = abs(AanchorAngle)

错误消息是

  

IndexError:用作索引的数组必须是整数(或布尔)类型

0 个答案:

没有答案