`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

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

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

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

Checking file existence in Julia

Julia has the isfile() function to test for a regular file: julia> isfile(“foo.txt”) false shell> touch foo.txt julia> isfile(“foo.txt”) true As the documentation: Returns true if path (the parameter) is a regular file, false otherwise.

Search for files in a folder

In Julia, the equivalent to list.files() is readdir([path]) There is no built-in directory search that I know of, but it is a one-liner: searchdir(path,key) = filter(x->contains(x,key), readdir(path)) UPDATE: Since at least Julia v0.7, contains() has been deprecated for occursin(substring, string). So the above filter would now be: searchdir(path,key) = filter(x->occursin(key,x), readdir(path))

What is the difference between “==” and “===” comparison operators in Julia?

@ChrisRackauckas’s answer is accurate as far as it goes – i.e. for mutable objects. There’s a bit more to the issue than that, however, so I’ll elaborate a bit here. The === operator (an alias for the is function) implements Henry Baker’s EGAL predicate [1, 2]: x === y is true when two objects are programmatically … Read more

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