Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 为什么将数组转换为字典会减少记录数?_Arrays_Python 3.x_Dictionary - Fatal编程技术网

Arrays 为什么将数组转换为字典会减少记录数?

Arrays 为什么将数组转换为字典会减少记录数?,arrays,python-3.x,dictionary,Arrays,Python 3.x,Dictionary,我得到的数组如下所示: first = [ 6.50480320e+05 3.00891760e+05 2.06200000e+01 5.86400395e-01 6.50480188e+05 3.00892264e+05 2.03518509e+01] 我使用此函数将其转换为以第4列为键的字典: d1 = dict((x[4], x[0:]) for x in first) 但当我检查长度时,我得到了奇怪的结果: print(len(first)) #len

我得到的数组如下所示:

first = [  6.50480320e+05   3.00891760e+05   2.06200000e+01   5.86400395e-01
   6.50480188e+05   3.00892264e+05   2.03518509e+01]
我使用此函数将其转换为以第4列为键的字典:

 d1 = dict((x[4], x[0:]) for x in first)
但当我检查长度时,我得到了奇怪的结果:

print(len(first)) #len = 99522
print(len(d1)) #len = 3285
然而,当我尝试在相似的数组上使用它时,长度是相似的

sec = [  6.50277398e+05   1.00000000e+00]
d2 = dict((x[0], x[1:]) for x in sec)

print(len(sec)) #len = 108371
print(len(d2)) #len = 107762

有人能解释一下原因吗?

字典有唯一的键。我猜你正在用数组中的副本覆盖你的字典。哇,可能就是这样!有没有办法不覆盖重复的键?没有字典不是这样的。如果这是必需的,您可能需要求助于2d数组--numpy.array()damit,因此我需要重写me函数以使用set或其他东西。set也是唯一的。。。