gpt4 book ai didi

dictionary - 如何在 Julia 中初始化字典?

转载 作者:行者123 更新时间:2023-12-04 22:03:29 25 4
gpt4 key购买 nike

当我尝试这样做时:

d = {1:2, 3:10, 6:300, 2:1, 4:5}

我收到错误:
syntax: { } vector syntax is discontinued

如何在 Julia 中初始化字典?

最佳答案

{}语法已经在 julia 中被弃用了一段时间。现在构造 dict 的方法是:

Given a single iterable argument, constructs a Dict whose key-value pairs are taken from 2-tuples (key,value) generated by the argument.

julia> Dict([("A", 1), ("B", 2)])
Dict{String,Int64} with 2 entries:
"B" => 2
"A" => 1

Alternatively, a sequence of pair arguments may be passed.

julia> Dict("A"=>1, "B"=>2)
Dict{String,Int64} with 2 entries:
"B" => 2
"A" => 1


(引用自文档,可以通过在终端中按 ? 进入“帮助”模式,然后输入 Dict 获得)

关于dictionary - 如何在 Julia 中初始化字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42086594/

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