# Construir matrices

Si ya conocemos el tamaño de la matriz:

``````

In [1]:

zeros(10)

``````
``````

Out[1]:

10-element Array{Float64,1}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0

``````
``````

In [2]:

zeros(3, 7)

``````
``````

Out[2]:

3x7 Array{Float64,2}:
0.0  0.0  0.0  0.0  0.0  0.0  0.0
0.0  0.0  0.0  0.0  0.0  0.0  0.0
0.0  0.0  0.0  0.0  0.0  0.0  0.0

``````
``````

In [3]:

zeros(2,3,4,5)

``````
``````

Out[3]:

2x3x4x5 Array{Float64,4}:
[:, :, 1, 1] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 2, 1] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 3, 1] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 4, 1] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 1, 2] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 2, 2] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 3, 2] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 4, 2] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 1, 3] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 2, 3] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 3, 3] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 4, 3] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 1, 4] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 2, 4] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 3, 4] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 4, 4] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 1, 5] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 2, 5] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 3, 5] =
0.0  0.0  0.0
0.0  0.0  0.0

[:, :, 4, 5] =
0.0  0.0  0.0
0.0  0.0  0.0

``````
``````

In [4]:

M = Int[]

``````
``````

Out[4]:

0-element Array{Int64,1}

``````
``````

In [5]:

push!(M, 10)

``````
``````

Out[5]:

1-element Array{Int64,1}:
10

``````
``````

In [9]:

M = Any[]

``````
``````

Out[9]:

0-element Array{Any,1}

``````
``````

In [10]:

push!(M, 10)
push!(M, 10.5)
push!(M, "hola")

``````
``````

Out[10]:

3-element Array{Any,1}:
10
10.5
"hola"

``````
``````

In [11]:

push!(M, [3, 4])

``````
``````

Out[11]:

4-element Array{Any,1}:
10
10.5
"hola"
[3,4]

``````
``````

In [20]:

M = Vector{Float64}[]

``````
``````

Out[20]:

0-element Array{Array{Float64,1},1}

``````
``````

In [21]:

push!(M, [3, 4, 5])

``````
``````

Out[21]:

1-element Array{Array{Float64,1},1}:
[3.0,4.0,5.0]

``````
``````

In [23]:

push!(M, [6, 7, 8])

``````
``````

Out[23]:

2-element Array{Array{Float64,1},1}:
[3.0,4.0,5.0]
[6.0,7.0,8.0]

``````
``````

In [18]:

A = Array(Any, 3, 4)

``````
``````

Out[18]:

3x4 Array{Any,2}:
#undef  #undef  #undef  #undef
#undef  #undef  #undef  #undef
#undef  #undef  #undef  #undef

``````
``````

In [19]:

A[1,2]

``````
``````

in getindex at array.jl:247

``````
``````

In [24]:

M

``````
``````

Out[24]:

2-element Array{Array{Float64,1},1}:
[3.0,4.0,5.0]
[6.0,7.0,8.0]

``````
``````

In [35]:

hcat(M[1], M[2])

``````
``````

Out[35]:

3x2 Array{Float64,2}:
3.0  6.0
4.0  7.0
5.0  8.0

``````
``````

In [37]:

vcat(M[1]', M[2]')

``````
``````

Out[37]:

2x3 Array{Float64,2}:
3.0  4.0  5.0
6.0  7.0  8.0

``````
``````

In [38]:

for i in 1:10
push!(M, [3,4,5])
end

``````
``````

In [39]:

M

``````
``````

Out[39]:

12-element Array{Array{Float64,1},1}:
[3.0,4.0,5.0]
[6.0,7.0,8.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]
[3.0,4.0,5.0]

``````
``````

In [41]:

hcat(M...)'

``````
``````

Out[41]:

12x3 Array{Float64,2}:
3.0  4.0  5.0
6.0  7.0  8.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0
3.0  4.0  5.0

``````
``````

In [ ]:

``````