Reworked some of the construction to be more succint:

function example(dims...)
    A = [zeros(2^l*[dims...]...) for l = 0:2]
    @show A


    J = [1 3 ; 2 4]
    I = kron(J, ones(Int,2,2))
    K = rand(4)
    B = K[I]
    @show B


    C = zeros( dims... )
    @show C
    
    nothing    
end



This is running on version 0.4-dev+1307

On Tuesday, November 11, 2014 3:19:38 PM UTC+2, Robert DJ wrote:
>
> Hi
>
> I've run into some array issues that I suspect are quite easy, but I 
> haven't found answers on Uncle Google or in the docs.
>
> In the example below I would like to do the following (more elegant):
>
> - Create the array of arrays A where the size of the inner arrays are 
> determined by the input 'dims...'. 
> Creating the D array seems cumbersome. 
>
> - Create the array B with a block structure defined by the array I. 
> The Kronecker product is automatically a Float even though both factors 
> are Int's and Float doesn't seem to work as indices; is there a better way 
> to circumvent this than ifloor?
>
> - repmath/reshape seems to like tuples, but not arrays as the new 
> dimensions. 
> Is there a way to convert between tuples and arrays?
>
> Thanks,
>
> Robert
>
>
> function example(dims...)
>     D = Array(Int, 2)
>     D[1] = dims[1]
>     D[2] = dims[2]
>     A = [zeros(2^l*D[1], 2^l*D[2]) for l = 0:2]
>     # Not working:
>     #A = [zeros(2^l*dims) for l = 0:2]
>
>     J = [1 3 ; 2 4]
>     I = ifloor(kron(J, ones(2,2)))
>     K = rand(4)
>     B = K[I]
>
>     C = zeros( prod(D) )
>     C = reshape(C, dims)
>     # Not working:
>     #C = reshape(C, D)
> end
>
>

Reply via email to