1. Matrix constructor
2. Matrix operations

 

1. Matrix constructor

more: http://docs.julialang.org/en/release-0.2/stdlib/base/#constructors
Array(type, dims)
Construct an uninitialized dense array. dims may be a tuple or a series of integer arguments.

cell(dims)
Construct an uninitialized cell array (heterogeneous array). dims can be either a tuple or a series of integer arguments.

zeros(type, dims)
Create an array of all zeros of specified type

ones(type, dims)
Create an array of all ones of specified type

reshape(A, dims)
Create an array with the same data as the given array, but with different dimensions.

Array(String, 2,2)
# 2x2 Array{String,2}:
#  #undef #undef
#  #undef #undef

cell(2,2,2)
# 2x2x2 Array{Any,3}:
# [:, :, 1] =
#  #undef #undef
#  #undef #undef

# [:, :, 2] =
#  #undef #undef
#  #undef #undef

zeros(1,3)
# 1x3 Array{Float64,2}:
#  0.0 0.0 0.0

eye(3)
# 3x3 Array{Float64,2}:
#  1.0 0.0 0.0
#  0.0 1.0 0.0
#  0.0 0.0 1.0

reshape(1:12, 3,4)
# 3x4 Array{Int64,2}:
#  1 4 7 10
#  2 5 8 11
#  3 6 9 12

repmat(A, n, m)
Construct a matrix by repeating the given matrix “n” times in
dimension 1 and “m” times in dimension 2.

vcat(A…)
Concatenate along dimension 1

hcat(A…)
Concatenate along dimension 2

A = reshape(1:6, 2, 3)
repmat(A, 3, 2)
B = reshape(7:12, 2, 3)

hcat(A, B) # Horizontal concatenation
vcat(A, B) # Vertical concatenation
#[1, 2, 3]
#[1, 2, 3]
#[1 2 3]
#[1 2 3; 4 5 6]

ndims(A) → Integer
Returns the number of dimensions of A
eltype(collection)
Determine the type of the elements generated by iterating collection. For associative collections, this will be a (key,value) tuple type.

length(A) → Integer
Returns the number of elements in A

size(A)
Returns a tuple containing the dimensions of A

vec(Array) → Vector
Vectorize an array using column-major convention.

sum(A, dims)
Sum elements of an array over the given dimensions.

A = reshape(1:6, 2, 3)
# 2x3 Array{Int64,2}:
#  1 3 5
#  2 4 6

ndims(A)  # 2
eltype(A) # Int64
length(A) # 6
size(A)   # (2,3)

vec(A)
# 6-element Array{Int64,1}:
#  1
#  2
#  3
#  4
#  5
#  6
sum(A, 1)
#  3 7 11
sum(A, 2)
#  9
#  12

 

2. Matrix operations

A = reshape(1:12, 3,4)
3x4 Array{Int64,2}:
 1 4 7 10
 2 5 8 11
 3 6 9 12

A[:,1]
3-element Array{Int64,1}:
 1
 2
 3

A[1:2, :]
2x4 Array{Int64,2}:
 1 4 7 10
 2 5 8 11

‘ : matrix transformation
.* .+ .- ./: element-wise calculation

A = reshape(1:12, 3,4)
B = reshape(1:12, 4,3)

A * A'
# 3x3 Array{Int64,2}:
#  166 188 210
#  188 214 240
#  210 240 270

A * B
# 3x3 Array{Int64,2}:
#  70 158 246
#  80 184 288
#  90 210 330

x = [1,1,1,1]
A * x
# 3-element Array{Int64,1}:
#  22
#  26
#  30