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.

Does a Python-like virtualenv exist in Julia?

Currently (julia 1.2) is able to manage virual environments via it’s builtin Pkg standard library module: https://docs.julialang.org/en/v1/stdlib/Pkg julia> ] (v1.2) pkg> activate tutorial [ Info: activating new environment at `/tmp/tutorial/Project.toml`. (tutorial) pkg> (tutorial) pkg> status Status `/tmp/tutorial/Project.toml` (empty environment) (tutorial) pkg> add Example … (tutorial) pkg> status Status `/tmp/tutorial/Project.toml` [7876af07] Example v0.5.1 There is Playground.jl … Read more

What is the difference between @code_native, @code_typed and @code_llvm in Julia?

The standard CPython implementation of Python parses source code and does some pre-processing and simplification of it – aka “lowering” – transforming it to a machine-friendly, easy-to-interpret format called “bytecode”. This is what is displayed when you “disassemble” a Python function. This code is not executable by the hardware – it is “executable” by the CPython interpreter. … Read more

Determine version of a specific package

EDIT: For Julia version 1.1+ Use the Pkg REPL notation: ] status # Show every installed package version ] status pkgName # Show the specific version of the package ] status pkgName1 pkgName2 # Show the named packages. You can continue the list. The ] enters the Pkg REPL, so you basically write status … … Read more

How can I dispatch on traits relating two types, where the second type that co-satisfies the trait is uniquely determined by the first?

Certainly! Here’s the complete code incorporating the approaches discussed: using Traits @traitdef IsProduct{X} begin isnew(X) -> Bool coolness(X) -> Float64 end @traitdef IsProductWithMeasurement{X,M} begin @constraints begin istrait(IsProduct{X}) end measurements(X) -> M end type Rope color::String age_in_years::Float64 strength::Float64 length::Float64 end type Paper color::String age_in_years::Int64 content::String width::Float64 height::Float64 end function isnew(x::Rope) x.age_in_years < 10.0 end function coolness(x::Rope) … Read more

Running Julia .jl files

If you want to run the julia script from a command line then just do /path/to/julia script-name.jl In the shell of your choice. If you want to run it from the julia repl then you want something like so: julia> include(“path/to/script-name.jl”) As to why your output is split like that I think we would need … Read more

What’s the point of firstindex in Julia?

The first index is not necessarily 1 because Julia supports custom indexing. To understand why it is useful, you can’t beat Tim Holy’s blog post. Custom indices allow you to encode information about your data in the indexing pattern itself: sometimes it is more natural to start counting from one, sometimes from zero, sometimes from … Read more

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