El viernes, 30 de octubre de 2015, 7:12:39 (UTC-6), Cameron Zachreson 
escribió:
>
> Hello, 
>
> Just started using Julia and I've come across an issue trying to create 
> and append values to arrays of empty arrays. 
>

If you specify a bit more precisely what you are trying to do, it will be 
easier to help you.

Note that performance will be terrible unless you completely specify the 
types of the objects -- just writing Array 
leaves some of the types unspecified, as denoted by the {T,N} when you write

julia> Array[]
0-element Array{Array{T,N},1}

The simplest solution is something like

julia> v = Vector{Int}[]
0-element Array{Array{Int64,1},1}

This specifies an empty array (the [ ] part) that contains vectors (i.e. 1D 
arrays) of Ints  (the Vector{Int} part).

You can then add vectors of integers to it with

julia> push!(v, [1, 2])
1-element Array{Array{Int64,1},1}:
 [1,2]

julia> push!(v, [3, 4, 5])
2-element Array{Array{Int64,1},1}:
 [1,2]  
 [3,4,5]
 

>
> What I want to do is create a grid of empty arrays that can be filled with 
> values associated with particle IDs for a molecular dynamics-style 
> simulation. The trouble I'm having is that it does not seem possible to 
> initialize the arrays so that they can be iteratively filled. 
>
> here is an example of the problem:
>
> julia> bins = Array(Array, 5, 5)
>
>
> 5x5 Array{Array{T,N},2}:
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>
> julia> bins[1, 1] = 0
>
>
> ERROR: MethodError: `convert` has no method matching 
> convert(::Type{Array{T,N}}, ::Int64)
>
> This may have arisen from a call to the constructor Array{T,N}(...),
>
> since type constructors fall back to convert methods.
>
> Closest candidates are:
>
>   call{T}(::Type{T}, ::Any)
>
>   convert(::Type{Array{T,N}}, ::SharedArray{T,N})
>
>   convert{T,N}(::Type{Array{T,N}}, ::AbstractArray{T,N})
>
>   ...
>
>  in setindex! at array.jl:314
>
> I don't understand what the error message means, I have tried initializing 
> with different datatypes, but it does not work. Any help would be 
> appreciated. 
>
> Cam
>
>
>
>

Reply via email to