我想遍历并打印 Julia 中字典的 (key, value) 对。我怎样才能做到这一点?
我在这里看到了如何在 Julia 中初始化字典,但我也想遍历它。
我正在尝试将 python 脚本转换为 Julia。我正在检查以确保我以最佳方式执行此代码。请看以下代码:
julia> a = [1,2,3,4,5]
5-element Array{Int64,1}:
1
2
3
4
5
julia> if 1 in a
print("1 is in a")
end
1 is in a
julia> if 6 not in a
print("6 not in a")
end
ERROR: TypeError: non-boolean (Int64) used in boolean context
Stacktrace:
[1] top-level scope at REPL[6]:1
julia> push!(a, 6)
6-element Array{Int64,1}:
1
2
3
4
5
6
julia> if (6 in a) == true
print("6 in a")
end
6 not in a …
Run Code Online (Sandbox Code Playgroud) 我试图测试一个字符串是否包含一个特定的子字符串,然后如果它包含它出现的索引。我怎么能在朱莉娅做到这一点?
我自学了机器学习,最近开始深入研究 Julia 机器学习生态系统。
skimage
经验,我想将 Julia ML 库(Flux/JuliaImages)与它的同行进行基准测试,看看它真正执行CV(任何)任务的速度有多快或多慢, 并决定是否我应该转而使用 Julia。
我知道如何使用这样的timeit
模块来获取在 python 中执行函数所花费的时间:
#Loading an Image using OpenCV
s = """\
img = cv2.imread('sample_image.png', 1)
"""
setup = """\
import timeit
"""
print(str(round((timeit.timeit(stmt = s, setup = setup, number = 1))*1000, 2)) + " ms")
#printing the time taken in ms rounded to 2 digits
Run Code Online (Sandbox Code Playgroud)
如何使用适当的库(在本例中为JuliaImages
)比较在 Julia 中执行相同任务的函数的执行时间。
Julia 是否为 …
我从文本文件中读取了以下行:"1200, 1200"
并且我想拆分字符串,", "
以便我可以访问原始数字。我怎样才能在朱莉娅中做到这一点?
我有 Julia 1.1
我想更新到最新版本的包,在这种情况下,Flux 8.3.0
根据Flux.jl 的文档
当我打字时
Pkg.status("Flux")
Run Code Online (Sandbox Code Playgroud)
我得到
Status `~/.julia/environments/v1.1/Project.toml`
[587475ba] Flux v0.6.10
Run Code Online (Sandbox Code Playgroud)
我也试过:
Pkg.add("Flux")
Pkg.update("Flux")
Run Code Online (Sandbox Code Playgroud)
但它不会改变版本
编辑 我在 Bogumi 发表评论后尝试了以下命令?神滑雪
Pkg.update()
Run Code Online (Sandbox Code Playgroud)
给我
Updating registry at `~/.julia/registries/General`
? Warning: Some registries failed to update:
? — `~/.julia/registries/General` — registry dirty
? @ Pkg.Types /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Types.jl:1269
Updating git-repo `https://github.com/MikeInnes/IRTools.jl.git`
Updating git-repo `https://github.com/JuliaInterop/RCall.jl.git`
Updating git-repo `https://github.com/FluxML/Zygote.jl.git`
Updating git-repo `https://github.com/VMLS-book/VMLS.jl`
Resolving package versions...
ERROR: Unsatisfiable requirements detected for package ZygoteRules [700de1a5]:
ZygoteRules [700de1a5] log:
??ZygoteRules [700de1a5] has no known versions! …
Run Code Online (Sandbox Code Playgroud) I am trying to compare two arrays. It just so happens that the data for the arrays contains NaN
values and when you compare arrays with NaN
values, the results are not what I would have expected.
julia> a = [1,2, NaN]
3-element Array{Float64,1}:
1.0
2.0
NaN
julia> b = [1,2, NaN]
3-element Array{Float64,1}:
1.0
2.0
NaN
julia> a == b
false
Run Code Online (Sandbox Code Playgroud)
Is there an elegant way to ignore these Nan
's during comparison or replace them efficiently?
我有同一个函数名称的多个函数/调度。我想确保它们全部出口。我是否只需要在导出语句中包含函数的名称,然后让 Julia 完成其余的工作?
例子:
function hello(a::Int64, b::Int64)
#nothing
end
function hello(a::Bool, b::Bool)
#nothing
end
export hello
Run Code Online (Sandbox Code Playgroud)
只要这样做,这两个都会被导出吗export hello
?
什么时候 Julia 中的函数应该有一个使用 return 关键字的 return 语句,什么时候它应该通过在函数末尾返回我想要返回的变量来返回?
我正在读茱莉亚文档,它似乎像有上找到的主题相当多的文献在这里。
我的理解是,return
如果您试图脱离函数,则约定始终使用,否则只使用您想要在函数末尾返回的变量。
我的理解是正确的还是我在这里遗漏了什么?
我正在阅读有关宏的文档,并在“阻止:为什么宏”部分下遇到了以下内容。使用宏的理由如下:
宏是必需的,因为它们在解析代码时执行,因此,宏允许程序员在运行完整程序之前生成并包含自定义代码的片段
这让我想知道为什么有人想要使用“在运行完整程序之前生成并包含自定义代码的片段”。有人可以提供有关为什么这对宏有益和/或其他良好用例的上下文吗?