How do I select a random item from a weighted array in Julia?

Use the StatsBase.jl package, i.e. Pkg.add(“StatsBase”) # Only do this once, obviously using StatsBase items = [“a”, 2, 5, “h”, “hello”, 3] weights = [0.1, 0.1, 0.2, 0.2, 0.1, 0.3] sample(items, Weights(weights)) Or if you want to sample many: # With replacement my_samps = sample(items, Weights(weights), 10) # Without replacement my_samps = sample(items, Weights(weights), 2, … Read more

set the random seed in julia generator of random numbers

Updated answer, for Julia 0.7 onwards. import Random Random.seed!(1234) dim = 5 A = randn(dim,dim) H = (A + A’)/sqrt(2) Previous answer, for Julia 0.6 and earlier. You are looking for the srand function, e.g. srand(1234) dim = 5 A = randn(dim,dim) H = (A + A’)/sqrt(2) Will always produce the same results.

Julia: Convert numeric string to float or int

You can parse(Float64,”1″) from a string. Or in the case of a vector map(x->parse(Float64,x),stringvec) will parse the whole vector. BTW consider using tryparse(Float64,x) instead of parse. It returns a Nullable{Float64} which is null in the case string doesn’t parse well. For example: isnull(tryparse(Float64,”33.2.1″)) == true And usually one would want a default value in case … Read more

Why is operating on Float64 faster than Float16?

As you can see, the effect you are expecting is present for Float32: julia> rnd64 = rand(Float64, 1000); julia> rnd32 = rand(Float32, 1000); julia> rnd16 = rand(Float16, 1000); julia> @btime $rnd64.^2; 616.495 ns (1 allocation: 7.94 KiB) julia> @btime $rnd32.^2; 330.769 ns (1 allocation: 4.06 KiB) # faster!! julia> @btime $rnd16.^2; 2.067 μs (1 allocation: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)