gpt4 book ai didi

dictionary - Julia 错误: map is not defined on dictionaries

转载 作者:行者123 更新时间:2023-12-02 20:10:16 35 4
gpt4 key购买 nike

julia> hotcell2vocab = Dict([(cell, i-1+vocab_start)
for (i,cell) in enumerate(hotcell)]);

julia> vocab2hotcell = map(reverse, hotcell2vocab)
ERROR: map is not defined on dictionaries

hotcell2vocab是一个Dict,有没有一种方法可以反转Dict中的键和值?

最佳答案

这是您要找的吗?

julia> d = Dict(i => i+10 for i in 1:5)
Dict{Int64,Int64} with 5 entries:
4 => 14
2 => 12
3 => 13
5 => 15
1 => 11

julia> d_rev = Dict(b=>a for (a,b) in d)
Dict{Int64,Int64} with 5 entries:
14 => 4
13 => 3
11 => 1
15 => 5
12 => 2

当然,这假设字典中的值是唯一的。

关于dictionary - Julia 错误: map is not defined on dictionaries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53755297/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com