Performance python在2d数组中测试数据

Performance python在2d数组中测试数据,performance,multidimensional-array,iteration,Performance,Multidimensional Array,Iteration,我有一个带有深度信息的二维阵列,640x480 我想将(行、列)值添加到一个列表中,其中的值在800到2800之间(在我的示例数据中,大约5%的值为true) 我有这段代码(python 2.7,w10,新笔记本电脑2017) depth=np.load(“depth.npy”)#depth.shape=(640480),ndarray 障碍列表[] 对于范围内的行(480): 对于范围内的列(640): 距离=深度[列,行] 如果距离>800且距离

我有一个带有深度信息的二维阵列,640x480

我想将(行、列)值添加到一个列表中,其中的值在800到2800之间(在我的示例数据中,大约5%的值为true)

我有这段代码(python 2.7,w10,新笔记本电脑2017)

depth=np.load(“depth.npy”)#depth.shape=(640480),ndarray
障碍列表[]
对于范围内的行(480):
对于范围内的列(640):
距离=深度[列,行]
如果距离>800且距离<2800:
obstacleList.append((列,区))
我的时间测量表明,完成这个列表几乎需要10秒

对于数据的进一步处理,我只需要具有最低dist值的col,但我认为这只会增加更多的处理时间


我的代码出了什么问题?

找到了numpy.nanmin,它可以在实际时间内找到每列的最小值。为了去掉一些值(如0),我需要将数组转换为浮点(因为NaN是浮点),并用NaN替换不需要的值

b=深度。aType(浮动)


b[By我们的代码不是正确的Python代码-它缺少一些标点符号。您如何确定它的处理需要时间,而不是
np.load
?抱歉,尝试更正它。已测量加载时间,需要0.04秒。
depth = np.load("depth.npy")    # depth.shape = (640, 480), ndarray
obstacleList[]
for row in range(480):
  for col in range(640):
    dist = depth[col, row]
    if  dist > 800 and dist < 2800: 
      obstacleList.append((col, dist))