Other ways to create arrays

For convenience, zeros(n) returns an n element array with all the elements equal to 0.0, and ones(n) does the same with elements equal to 1.0.

range(start, stop=value, length=value) creates a vector of n equally spaced numbers from start to stop, for example, as follows:

eqa = range(0, step=10, length=5) #> 0:10:40show(eqa) #> 0:10:40

You can use the following to create an array with undefined values #undef, as shown here:

println(Array{Any}(undef, 4)) #> Any[#undef,#undef,#undef,#undef] 

To fill an array arr with the same value for all the elements, use fill!(arr, 42), which returns [42, 42, 42, 42, 42].

To create a five-element array with random Int32 numbers, execute the following:

v1 = rand(Int32,5) 
5-element ...

Get Julia 1.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.