Discussion:
[julia-users] question about altering the shape of a 3-d array
j***@gmail.com
2015-07-31 23:05:09 UTC
Permalink
Hi All:

I have a 3-d array (Float64), call it q, with dimensions (d1, d2, d3)

that needs to be to changed to an array, call it Q, with dimensions (d2,
d3, d1) to perform several computations.

I have tried using the reshape command but that does not respect the first
dimension (row) of the q array becoming the third dimension of the array Q.

The only solution I have found is to define an array Q = Array(Float64, d2,
d3, d1).

Next, create

q1 = squeeze(q[1,:,:],1)

q2 = squeeze(q[2,:,:],1)

...

qd1 = squeeze(q[d1,:,:],1)

and then set

Q[1,:,:] = q1

Q[2,:,:] = q2

...

Q[d1,:,:] = qd1.

Although this "works," it seems neither elegant nor efficient code. Also,
these computations are within a particle filter simulator in which d1 = 7,
but d2 = 180, and d3 >= 20,000.

Suggesting my solution will slow the simulations.

Your advice/suggestions are appreciated.

Thanks.

Jim Nason
Tim Holy
2015-07-31 23:09:08 UTC
Permalink
Are you looking for permutedims?

--Tim
Post by j***@gmail.com
I have a 3-d array (Float64), call it q, with dimensions (d1, d2, d3)
that needs to be to changed to an array, call it Q, with dimensions (d2,
d3, d1) to perform several computations.
I have tried using the reshape command but that does not respect the first
dimension (row) of the q array becoming the third dimension of the array Q.
The only solution I have found is to define an array Q = Array(Float64, d2,
d3, d1).
Next, create
q1 = squeeze(q[1,:,:],1)
q2 = squeeze(q[2,:,:],1)
...
qd1 = squeeze(q[d1,:,:],1)
and then set
Q[1,:,:] = q1
Q[2,:,:] = q2
...
Q[d1,:,:] = qd1.
Although this "works," it seems neither elegant nor efficient code. Also,
these computations are within a particle filter simulator in which d1 = 7,
but d2 = 180, and d3 >= 20,000.
Suggesting my solution will slow the simulations.
Your advice/suggestions are appreciated.
Thanks.
Jim Nason
Jim Nason
2015-07-31 23:13:27 UTC
Permalink
Dear Tim:

Yes, I am.

Thank you.

There is a lot to learn about Julia, but it is all worth it.

Best wishes,

Jim
Post by Tim Holy
Are you looking for permutedims?
--Tim
Post by j***@gmail.com
I have a 3-d array (Float64), call it q, with dimensions (d1, d2, d3)
that needs to be to changed to an array, call it Q, with dimensions (d2,
d3, d1) to perform several computations.
I have tried using the reshape command but that does not respect the first
dimension (row) of the q array becoming the third dimension of the array Q.
The only solution I have found is to define an array Q = Array(Float64, d2,
d3, d1).
Next, create
q1 = squeeze(q[1,:,:],1)
q2 = squeeze(q[2,:,:],1)
...
qd1 = squeeze(q[d1,:,:],1)
and then set
Q[1,:,:] = q1
Q[2,:,:] = q2
...
Q[d1,:,:] = qd1.
Although this "works," it seems neither elegant nor efficient code. Also,
these computations are within a particle filter simulator in which d1 = 7,
but d2 = 180, and d3 >= 20,000.
Suggesting my solution will slow the simulations.
Your advice/suggestions are appreciated.
Thanks.
Jim Nason
Continue reading on narkive:
Loading...