perjantai 22. heinäkuuta 2016 11.28.58 UTC+3 Ferran Mazzanti kirjoitti:
>
> Sorry for being so noob once again, but I'm getting close without getting 
> actually to it.
> Could somebody tell me please how should I change the previous definition 
> of caw() as given by Jussi to make room
> for a Vector of Arrays (I can fix them to dimension 2) instead of a Vector 
> of Vector?  I'd like to be able to define it simllarly,
> so that instances of caw() are initially empty and I push!() 2-dimensional 
> arrays into it...
>

 My hobby: empty things.

Array type has two parameters: element type and number of dimensions. 
Vector{Float64} is shorthand for Array{Float64,1}, and Matrix{Float64} is 
similar shorthand for Array{Float64,2}. A vector can be made by listing the 
elements in square brackets after the element type:
julia> Matrix{Float64}[]
0-element Array{Array{Float64,2},1}

Or as Stefan did using the type of the vector:
julia> Vector{Matrix{Float64}}()
0-element Array{Array{Float64,2},1}

There is no Matrix there but you can push! a Matrix there. Or you can start 
with a non-empty Vector that contains an empty Matrix:
julia> Matrix{Float64}[Matrix{Float64}()]
1-element Array{Array{Float64,2},1}:
 0x0 Array{Float64,2}

The expression inside the square brackets makes an empty Matrix. I think 
they are changing this, but in the current release the type name before the 
square brackets makes a big difference when the element is an Array.

I'm not sure how the square brackets would be used if you wanted a matrix 
of matrices, but you could at least start with an empty one by writing 
Matrix{Matrix{Float64}}(). And for an empty vector of matrices, as said, 
Vector{Matrix{Float64}}. And Julia will show these types as Array{T,1} and 
Array{T,2} instead of Vector and Matrix.


Reply via email to