python - 如何哈希列表?

标签 python list hash nearest-neighbor locality-sensitive-hash

列表不可散列。然而,我是implementing LSH我正在寻找一个散列函数,它将正整数列表(在 [1, 29.000] 中)对应到 k 个桶。列表的数量是 D,其中 D > k(我认为)和 D = 40.000,其中 k 尚不清楚(欢迎提出建议)。


示例(D = 4,k = 2):

118 | 27 | 1002 | 225
128 | 85 | 2000 | 8700
512 | 88 | 2500 | 10000
600 | 97 | 6500 | 24000
800 | 99 | 7024 | 25874

第一列应作为哈希函数的输入并返回桶的编号。


让我感到困惑的是,我们不是在寻找一个函数来对数字进行哈希处理,而是在寻找一个列,即正整数列表。

有什么想法吗?

我正在使用 如果这很重要

最佳答案

您可以在之前将其转换为可哈希类型:

In [4]: hash(l)
TypeError: unhashable type: 'list'

hash(tuple(l)) % k  # 29000
Out[5]: 70846

关于python - 如何哈希列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37125539/

相关文章:

python - 如何为 Python 的 MD5 模块设置加密 key ?

ruby-on-rails - Ruby on Rails 教程 : Defining a hash with symbol keys

python - 错误: non-constant-expression cannot be narrowed from type 'npy_intp' to 'int'

python - 启动时 raspbian python 脚本 EOF 错误

python - 将数学应用于 python 中的列表成员

java - 如何从 BIG HTML 字符串中删除一些标签?

python - 元组列表,第一个元组作为键,按键分组到字典中

security - 客户端密码哈希与纯文本

python - PyGame: Sprite 不会移动

python - 根据多个条件分配值