Re: Condensing indices in a matrix

Kai Torben Ohlhus <[email protected]>
Newsgroups gmane.comp.gnu.octave.general
Message-ID <[email protected]>
On 12/8/20 6:10 AM, Brett Green wrote:
> Is it possible to construct a matrix of the following form without for 
> loops?
> 
> Start with a multidimensional array
> M( T1 , n1 , m1 , T2 , n2 , m2 )
> where we have the same size in the T1 and T2 dimensions, the n1 and n2 
> dimensions, and the m1 and m2 dimensions.
> 
> Then, for each n and m, set
> M( 1 , n , m , 2 , n , m ) = a;
> M( 2 , n , m , 1 , n+1 , m ) = b;
> M( 2 , n , m , 1 , n , m+1 ) = c;
> for some numbers a, b and c. I can do this with e.g.
> M( 1 , : , : , 2 , : , : ) = a;
> so this is not a problem.
> 
> Then condense the multidimensional array to a 2D array
> M( u(T1,n1,m1) , u(T2,n2,m2) )
> where u is some function that condenses the indices from tuples of 3 to 
> single indices. The function u can be anything that condenses our 
> indices this way, though it'd be especially nice if I could define it 
> myself.
> 
> I am familiar with using reshape to condense all indices. Is there also 
> a way to condense only certain indices? Or, is there another way to 
> construct this matrix besides reshaping a multidimensional array?
> 
> - Brett Green
> 


Was it possible to send some minimal working example how array M is 
created?  For u(x,y,z), maybe `sub2ind` [1] can be helpful.

HTH,
Kai

[1] https://octave.org/doc/v6.1.0/Advanced-Indexing.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.