Arrays


In [68]:
#Array declaration

a = [1,4,2,9,3,5]


Out[68]:
6-element Array{Int64,1}:
 1
 4
 2
 9
 3
 5

In [69]:
b = [1 4 2 7 3 5]


Out[69]:
1×6 Array{Int64,2}:
 1  4  2  7  3  5

In [70]:
c = [1 2; 2 4; 5 6]


Out[70]:
3×2 Array{Int64,2}:
 1  2
 2  4
 5  6

Basic Functions


In [71]:
# ndims returns the number of dimensions of an array
ndims(c)


Out[71]:
2

In [72]:
# size returns a tuple with the dimensions of an array
size(c)


Out[72]:
(3,2)

In [73]:
#Returns a subset of array

getindex(a, 2:3)


Out[73]:
2-element Array{Int64,1}:
 4
 2

In [74]:
# the view function is like getindex(), but returns a view into the parent array with the given indices instead of making a copy.
x =view(a, 2:3)


Out[74]:
2-element SubArray{Int64,1,Array{Int64,1},Tuple{UnitRange{Int64}},true}:
 4
 2

In [75]:
#Creates a SubArray from an indexing expression, should not be used as the target of an assignment (e.g. @view(A[1,2:end]) = ...)

@view a[2:end]


Out[75]:
5-element SubArray{Int64,1,Array{Int64,1},Tuple{UnitRange{Int64}},true}:
 4
 2
 9
 3
 5

In [76]:
#parent returns the ”parent array” of an array view type
parent(x)


Out[76]:
6-element Array{Int64,1}:
 1
 4
 2
 9
 3
 5

In [77]:
# parentindexes returns the corresponding indexes in the parent
parentindexes(x)


Out[77]:
(2:3,)

In [78]:
# slicedim() return all the data where the index for dimension d equals i

slicedim(c,1,2)


Out[78]:
2-element Array{Int64,1}:
 2
 4

In [79]:
# setindex!(A, X, inds...) stores values from array X within some subset of A as specified by

y = [7,8]
setindex!(a, y,2:3)


Out[79]:
6-element Array{Int64,1}:
 1
 7
 8
 9
 3
 5

In [81]:
# isassigned(array, i) tests whether the given array has a value associated with index i
isassigned(a, 10)


Out[81]:
false

In [83]:
# vcat(A...) concatenates along dimension 1


Out[83]:
8-element Array{Int64,1}:
 1
 7
 8
 9
 3
 5
 7
 8

In [ ]: