Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Julia

You're reading from  Mastering Julia

Product type Book
Published in Jul 2015
Publisher
ISBN-13 9781783553310
Pages 410 pages
Edition 1st Edition
Languages

Arrays


An array is an indexable collection of (normally) homogeneous values such as integers, floats, booleans. In Julia, unlike many programming languages, the index starts at 1 not 0.

One simple way to create an array is to enumerate its values:

julia> A = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377];
15-element Array{Int64,1}

These are the first 15 values of the Fibonacci series and because all values are listed as integers the array created is of type Int64. The other number refers to the number of dimensions of the array, in this case 1.

In conjunction of loops in the Asian option example in the previous chapter, we meet the definition of a range as: start:[step]:end

julia> A = [1:10]; B = [1:3:15]; C =[1:0.5:5];

Here A is [1,2,3,4,5,6,7,8,9,10], B is [1,4,7,10,13] and C is [1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0]

Because the step in C is specified as a float value the array is of type Float64 not Int64.

Julia also provides functions such as zeros, ones and rand which provide...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}