【发布时间】:2021-01-24 12:55:54
【问题描述】:
我想遍历存储在列表和字典中的 numpy 数组。我的名单被命名为result:
result= [array([[ 1. , 0.75 , 69.5198822 ],
...,
[99. , 29.25 , 49.51967621]]),
...
array([[ 1. , 0.75 , 78.88569641],
...,
[99. , 29.25 , 58.88546753]]),
...
array([[ 1. , 0.75 , 77.7075882 ],
...,
[99. , 29.25 , 57.70734406]])]
我的字典也叫dicti:
{'sub_arr1': array([[37. , 2.25 , 2.62501693],
...,
[81.68138123, 29.25 , 99. ]]),
...
'sub_arr2': array([[41. , 2.25 , 2.254704 ],
...,
[85.93613434, 29.25 , 99. ]]),
...
'sub_arr3': array([[51. , 2.25 , 1.13132851],
...,
[96.60651398, 29.25 , 99. ]])}
然后,我想在存储在这两个数据集(result 和dicti)中的数组之间进行计算。我想删除result数组的一些数据点,这些数据点比dicti数组的阈值(例如10)更接近,并将它们存储为新数组。其实我想比较result的第一个数组和dicti的第一个数组,第二个跟第二个,第三个跟第三个等等。我可以说我想清理存储在result 列表中的数组,然后将新的清理数组另存为 3d numpy 数组中的单独数组,或者可能再次保存为清理数组的列表。我的代码(不工作!!!)如下:
import numpy as np
new_result=np.array ([])
for i in result:
for key, value in dicti():
clp=result[i][np.where(np.min(distance.cdist(value, result[i]),axis=0)<10)[0],:] # it finds the points of result that are closer 10 to points stored as values of dicti
cleaned_result= npi.difference(result[i], clp) # it removes that close points
new_result=np.append (new_result, cleaned_result).
我面临的错误是TypeError: only integer scalar arrays can be converted to a scalar index,但我认为我的代码还有其他问题。
提前感谢任何反馈。
【问题讨论】:
标签: python arrays numpy dictionary