julia

Why does my julia code run so slowly?

為{幸葍}努か 提交于 2020-01-13 12:02:09
问题 redim = 2; # Loading data iris_data = readdlm("iris_data.csv"); iris_target = readdlm("iris_target.csv"); # Center data iris_data = broadcast(-, iris_data, mean(iris_data, 1)); n_data, n_dim = size(iris_data); Sw = zeros(n_dim, n_dim); Sb = zeros(n_dim, n_dim); C = cov(iris_data); classes = unique(iris_target); for i=1:length(classes) index = find(x -> x==classes[i], iris_target); d = iris_data[index,:]; classcov = cov(d); Sw += length(index) / n_data .* classcov; end Sb = C - Sw; evals,

Extracting parameter types in Julia

荒凉一梦 提交于 2020-01-13 09:16:27
问题 Suppose I write a function in Julia that takes a Dict{K,V} as an argument, then creates arrays of type Array{K,1} and Array{V,1} . How can I extract the types K and V from the Dict object so that I can use them to create the arrays? 回答1: Sven and John's answers are both quite right. If you don't want to introduce method type parameters the way John's code does, you can use the eltype function: julia> d = ["foo"=>1, "bar"=>2] ["foo"=>1,"bar"=>2] julia> eltype(d) (ASCIIString,Int64) julia>

Extracting parameter types in Julia

霸气de小男生 提交于 2020-01-13 09:16:11
问题 Suppose I write a function in Julia that takes a Dict{K,V} as an argument, then creates arrays of type Array{K,1} and Array{V,1} . How can I extract the types K and V from the Dict object so that I can use them to create the arrays? 回答1: Sven and John's answers are both quite right. If you don't want to introduce method type parameters the way John's code does, you can use the eltype function: julia> d = ["foo"=>1, "bar"=>2] ["foo"=>1,"bar"=>2] julia> eltype(d) (ASCIIString,Int64) julia>

Julia: Using pmap correctly

荒凉一梦 提交于 2020-01-13 02:09:09
问题 Why doesn't this do what I think it should: benjamin@benjamin-VirtualBox:~$ julia -p 3 julia> @everywhere(function foom(bar::Vector{Any}, k::Integer) println(repeat(bar[2],bar[1])); return bar; end) julia> foo={{1,"a"},{2,"b"},{3,"c"}} julia> pmap(foom, foo, 5) From worker 2: a 1-element Array{Any,1}: {1,"a"} and that is all it outputs. I was expecting pmap to iterate through each tuple in foo and call foom on it. EDIT: It works correctly when I don't pass other arguments in: julia>

Is there any way to build package dependency tree in julia-lang?

淺唱寂寞╮ 提交于 2020-01-12 18:46:30
问题 Using npm list will show a tree of installed packages, versions and relations: Although Julia package management is differ (e.g normally no duplicate copy of a package exists), But is there any way to: Know why one package have been installed? or build a package dependency tree. 回答1: I don't think there's a simple function, but it shouldn't be too hard to do with these two functions: julia> Pkg.dependents("Cairo") 10-element Array{AbstractString,1}: "Tk" "Gtk" "Mamba" "Drawing" "GtkUtilities"

Is there any way to build package dependency tree in julia-lang?

家住魔仙堡 提交于 2020-01-12 18:45:55
问题 Using npm list will show a tree of installed packages, versions and relations: Although Julia package management is differ (e.g normally no duplicate copy of a package exists), But is there any way to: Know why one package have been installed? or build a package dependency tree. 回答1: I don't think there's a simple function, but it shouldn't be too hard to do with these two functions: julia> Pkg.dependents("Cairo") 10-element Array{AbstractString,1}: "Tk" "Gtk" "Mamba" "Drawing" "GtkUtilities"

Julia scoping specifics: defining closure within loop

隐身守侯 提交于 2020-01-11 10:43:22
问题 I am learning Julia using Ivo Balbaert's book. He uses the following example: anon = Array{Any}(undef, 2) for i = 1:2 anon[i] = () -> println(i) i += 1 end Now calling the two functions in this array outputs: julia> anon[1](); anon[2]() 2 3 I fail to understand why the output is 2, 3 instead of 1, 2. At the first pass through the loop i = 1 , so that anon[1] = () -> println(1) . The author continues: Here, both anon[1] and anon[2] are anonymous functions. When they are called with anon[1]()

How does one perform the exp() operation element-wise in Juila?

China☆狼群 提交于 2020-01-11 09:41:49
问题 I'm new to Julia and this seems like a straight-forward operation but for some reason I am not finding the answer anywhere. I have been going through some tutorials online and they simply use exp(A) where A is a nxm matrix but this gives me a DimensionMismatch error. I looked through the documentation on the official website in the elementary functions as well as the linear algebra section and googled it multiple times but can't find it for the life of me. 回答1: In julia, operations on

Exact decimal arithmetic in Julia

浪尽此生 提交于 2020-01-11 04:55:08
问题 Due to the nature of floating-point math, .4 * .4 = 0.16000000000000003 in Julia. I want to get the mathematically correct answer of 0.16 , in a CPU-efficient way. I know round() works, but that requires prior knowledge of the number of decimal places the answer occupies, so it isn't a general solution. 回答1: Some options: Use the inbuilt Rational type. The most accurate and fastest way would be 16//100 * 16//100 If you're using very big numbers these might overflow, in which case you can use

数据科学新的工具Julia

北战南征 提交于 2020-01-07 17:58:48
之前就关注过这个Julia,这两天帮同学编译一个OpenCV的代码,感觉C++有很多无法替代的场景。然而目前以后很多尝试去 替代 C++的部分使用场景,其中Go和Julia就是其中的两个 今天早上搜了一下,Julia现在已经是1.3版本的,之前安装的时候网速特别慢,现在也有了中国的镜像~ 安装Julia和Julia的包的网速应该不成问题,,而且伴随着1.0版本的发布,其语言特性和相关生态应该也越来越稳定了~ julia中文的社区提供了相应的中文的文档,下载以及镜像的设置方式; https://cn.julialang.org https://cn.julialang.org/downloads/ https://discourse.juliacn.com/t/topic/736 https://zhuanlan.zhihu.com/p/79913766 对于自己的下一个项目可以尝试一下 这个Julia 关于Julia的入门学习还是靠书籍,有兴趣的可以去图书馆找几本看看,或者在豆瓣或者京东看看评论 来源: https://www.cnblogs.com/wybert/p/12148224.html