【发布时间】:2018-08-21 15:09:03
【问题描述】:
我创建了两个数组,如下所示:
DotsLat1=np.concatenate((HLat,DotsLatMA,DotsLatMC,DotsLatMB,DotsLatMD,DotsLatMAB,DotsLatMAD,DotsLatMBC,DotsLatMDC), axis=0)
DotsLon1=np.concatenate((HLon,DotsLonMA,DotsLonMC,DotsLonMB,DotsLonMD,DotsLonMAB,DotsLonMAD,DotsLonMBC,DotsLonMDC), axis=0)#
分别给出以下纬度和经度:
array([51.43584 , 51.47806059, 51.47554269, 51.39361941, 51.39613731,
51.43584 , 51.44428412, 51.45272824, 51.46117236, 51.46961647,
51.39361941, 51.40206353, 51.41050764, 51.41895176, 51.42739588,
51.43584 , 51.45172108, 51.46760215, 51.43584 , 51.41995892,
51.40407785, 51.47604627, 51.4601652 , 51.46860931, 51.47705343,
51.41252196, 51.42840304, 51.43684716, 51.44529128, 51.45915804,
51.44327696, 51.43483284, 51.42638872, 51.39563373, 51.4115148 ,
51.40307069, 51.39462657])
array([2.59277 , 2.72014661, 2.55890633, 2.46539339, 2.62663367,
2.59277 , 2.61824532, 2.64372065, 2.66919597, 2.69467129,
2.46539339, 2.49086871, 2.51634403, 2.54181935, 2.56729468,
2.59277 , 2.57922453, 2.56567906, 2.59277 , 2.60631547,
2.61986094, 2.59115438, 2.60469985, 2.63017518, 2.6556505 ,
2.64533626, 2.63179079, 2.65726611, 2.68274144, 2.54020374,
2.55374921, 2.52827389, 2.50279856, 2.59438562, 2.58084015,
2.55536482, 2.5298895 ])
有些点具有相同的经度和相同的纬度(例如第一个点)。如果纬度和经度都有重复项,我想删除两个数组中的这些点(所以如果这些点在地图中相互绘制)。因此,保持正确的顺序很重要。
当我使用时
DotsLat2=np.unique(DotsLat1)
DotsLon2=np.unique(DotsLon1)
顺序不再正确,我的积分散了。
当我使用时
DotsLat2=list(set([DotsLat1]))
DotsLon2=list(set([DotsLon1]))
错误是
unhashable type: 'numpy.ndarray'
知道如何摆脱错误并创建我的独特点吗?
【问题讨论】:
-
要从 numpy ndarray 中获取列表,请使用 tolist() 方法:DotsLat1.tolist()
-
我会将 lats 和 long 放在同一个数组中,添加一个额外的维度,而不是两个单独的数组,然后你可以使用 np.unique
标签: python list duplicates coordinates unique