Imagine you have a 3-dimensional Julia A array of type Float64, where size(A) = (2, 3, 3) .
How could you assign blocks to this array at a time using two-dimensional arrays? For example, let's say I wanted A[1, :, :] be the identity matrix. I would think of doing something like this:
A = Array(Float64, 2, 3, 3) A[1, :, :] = eye(3)
When I do this, I get the following error:
ERROR: argument dimensions must match in setindex! at array.jl:592
I know that this is because size(A[1, :, :]) = (1, 3, 3) , but I canβt figure out how to either 1) get this slice as easy as (3, 3) , therefore eye(3) fits or 2) make eye(3) also be (1, 3, 3) to fit the shape of slice A
Any suggestions?
EDIT 12:51 AM PST 8-13-13
I learned two new things:
- If I take a slice
A along either of the other two dimensions, the result will be a 2-dimensional array instead of a 3-d array with a leading size of 1. - I found a workaround for my specific problem by doing
A[1, :, :] = reshape(eye(3), (1, 3, 3)) . This is not optimal, and I hope for a better fix.
source share