python内置哈希和哈希库.md5()不同的结果?

2024-09-26 18:12:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在数据集中找到重复的图像。所以我试着把它们切成桶。使用内置的哈希函数,我可以得到大约1000个重复,但是使用哈希库.md5()我根本没有复制品? 为什么? 我使用的数据集是noMNIST,这两个数据集是从那里取的,一个比另一个大得多,即大小为200000和10000

这是我的代码:

# check for duplicates in the 2 dataset images

import hashlib
def checkDuplicates(data1, data2):
    data1.flags.writeable = False
    data2.flags.writeable = False
    duplicates = 0
    table = {}
    for i in range(0,len(data1),1):
        h = hashlib.md5(data1[i,:,:].data)
        table[h] = i
    for id,image in enumerate(data2):
        h = hashlib.md5(image.data)
        if (h in table) and (data1[table[h],:,:].data == image.data):
            duplicates += 1
    print (duplicates)
    return duplicates

如果我换掉这个哈希库.md5()只使用hash()函数,它可以给我1000-1200个重复项!!!为什么会有这样的区别?在


Tags: 数据函数inimagefalsefordatatable

热门问题