`where` in function definitions in julia-0.6

The new syntax means the same thing but can be used in more circumstances and can express more constructs and eliminates a number of conceptual ambiguities, especially surrounding parametric constructors. The old syntax will be deprecated in 0.6 and some of the old syntax will be reclaimed with different meaning in 1.0. Fundamentally, the problem … Read more

Best way to run Julia code in an IPython notebook (or Python code in an IJulia notebook)

Run Julia inside an IPython notebook Hack In order to run Julia snippets (or other language) inside an IPython notebook, I just append the string ‘julia’ to the default list in the _script_magics_default method from the ScriptMagics class in: /usr/lib/python3.4/site-packages/IPython/core/magics/script.py or /usr/lib/python2.7/site-packages/IPython/core/magics/script.py. Example: # like this: defaults = [ ‘sh’, ‘bash’, ‘perl’, ‘ruby’, ‘python’, ‘python2’, … Read more

What’s the most efficient way to convert a Matrix{T} of size 1*N or N*1 in Julia to a Vector{T}?

You can use the vec() function. It’s faster than the list comprehension and scales better with number of elements šŸ˜‰ For a matrix of 1000×1: julia> const a = reshape([1:1000],1000,1); julia> typeof(a) Array{Int64,2} julia> vec_a = [x::Int for x in a]; julia> typeof(vec_a) Array{Int64,1} julia> vec_aII = vec(a); julia> typeof(vec_aII) Array{Int64,1} 6.41e-6 seconds # list … Read more

Delete element in an array for julia

You can also go with filter!: a = Any[“D”, “A”, “s”, “t”] filter!(e->e≠”s”,a) println(a) gives: Any[“D”,”A”,”t”] This allows to delete several values at once, as in: filter!(e->eāˆ‰[“s”,”A”],a) Note 1: In Julia 0.5, anonymous functions are much faster and the little penalty felt in 0.4 is not an issue anymore šŸ™‚ . Note 2: Code above … Read more

Initialize an array of arrays in Julia

If you want an array of arrays as opposed to a matrix (i.e. 2-dimensional Array): a = Array[ [1,2], [3,4] ] You can parameterize (specify the type of the elements) an Array literal by putting the type in front of the []. So here we are parameterizing the Array literal with the Array type. This … Read more

What’s the difference between Array{Bool} and BitArray in Julia and how are they related?

An Array{Bool} stores each true/false value as a Bool, which is represented internally as a UInt8. So if your array has N elements, it will take N bytes to store it. A BitArray stores each true/false value as a single bit, with (conceptually) 8 of them packed into a single UInt8. Consequently, it takes only … Read more

Julia: How to pretty print an array?

Use display(x). Let me comment here on what is going on here. A key difference is between show(io, x) and show(io, mime, x), as you can see in the docs: help?> show(stdout, a) show([io::IO = stdout], x) Write a text representation of a value x to the output stream io. New types T should overload … Read more

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