help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reshaping a 4D array to 2D


From: Brett Green
Subject: Re: Reshaping a 4D array to 2D
Date: Thu, 12 Mar 2020 17:41:17 -0400

On Thu, Mar 12, 2020 at 4:17 PM Nicholas Jankowski <address@hidden> wrote:

Just to confirm - the script for the small array you wrote above provides the mapping that you're looking for? If so are you concerned that something about the reshape might not scale to larger arrays? If not, what do you actually want it to look like? can you provide a desired output example?
 
On Thu, Mar 12, 2020 at 4:29 PM Przemek Klosowski via Help-octave <address@hidden> wrote:
On 3/12/20 3:42 PM, Brett Green wrote:
> The documentation simply states that column-major order is used, which
> if I understand correctly preserves the last index (in the case of a
> matrix the column, in this case data), as I wanted.

What do you mean by 'preserving the last index'?  Column-major means
that the first index changes first, i.e. for a square matrice reshape()
picks elements down the first column, then second column, etc.:

reshape([1 2 ;3 4],1,4)
ans =

    1   3   2   4

For your 4-dimensional array, the elements are taken in this order:
H(1,1,1,1),H(2,1,1,1),H(3,1,1,1), etc. and put in the reshaped array
also in the 'first column, then second column, and so on' order.

  reshape([1 2 ;3 4;5 6;7 8],2,4)
ans =

    1   5   2   6
    3   7   4   8

Nicholas Jankowski:
Yes, that's correct. I'm in practice going to be dealing with m by n by 4 by 10 arrays where m and n are ~100.

Przemek Klosowski:
I see; so they are taken and then populated in the same order - H(1,1,1,1), H(2,1,1,1), H(3,1,1,1) are reshaped into D(1,1), D(2,1), D(3,1). In both cases the indices are increased from left to right or first to last. I can see why this satisfies both of the properties I need - thank you!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]