Hi forum

 

I have an arbitrary matrix

 

   mat=. 4 5 $ i.100

 

   mat

 0  1  2  3  4

 5  6  7  8  9

10 11 12 13 14

15 16 17 18 19

 

I want to average only specific rows and columns of this matrix. Here is the
Boolean mask

 

   mask=. 0 1 1 1, 1 1 1 1 1, 0 0 0 0 0,: 1 1 1 1 0

 

   mask

0 1 1 1 0

1 1 1 1 1

0 0 0 0 0

1 1 1 1 0

 

What I would like is mat's row average for the non-zero entries in the mask.


 

I have tried combinations of #  and had thought that -. (remove) would work.
I bounced into some issues. For instance

 

mask #"1 mat

 

produces

 

1  2  3  0 0

 5  6  7  8 9

 0  0  0  0 0

15 16 17 18 0

 

Which properly identifies the row entries but shifts row 0 to the left by
one. 

 

How do I get a non-zero row averages of this matrix?

 

Ultimately, I will be working with multi-dimensional matrices and extracting
info of different shapes and sizes from the various dimensions. Rather than
doing these selections on a case by case basis, I am hoping to use some form
of a multi-dimensional mask to select the data and then do the calculations.
There may be other more efficient approaches which would be great to hear
about.

 

Any help on this is much appreciated.

 

Thanks

 

Bob

 

 

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to