x is the data and b is the correspond mask. b=: ?3 4 5$2 x=: ?3 4 5$100 (+/"1 b*x) % +/"1 b
----- Original Message ----- From: Robert O'Boyle <[email protected]> Date: Wednesday, December 2, 2009 8:34 Subject: Re: [Jprogramming] averages of non-zero elements of matrices To: 'Programming forum' <[email protected]> > Thanks, Brian - slip of the finger on the leftmost entry. Here > is the > correct mask > > mask=. 0 1 1 1 0, 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 > > Which indicates that from matrix mat, I would like the average > of columns 1 > 2 3 of row one, all columns of row 2, none of row 3 and 0, 1, 2 > and 3 of row > 4. > > Thus for mat > > 0 1 2 3 4 > 5 6 7 8 9 > 10 11 12 13 14 > 15 16 17 18 19 > > I would like 3 numbers output - 2 for row 1, 7 for row 2 and > 16.5 for row 4 > > Thanks > > Bob > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Brian Schott > Sent: December 2, 2009 12:22 PM > To: Programming forum > Subject: Re: [Jprogramming] averages of non-zero elements of matrices > > Bob, > > Please give your desired output with the example, because your problem > specification is a little ambigous, especially with your > definition of > mask, because its leftmost entry has only 4 elements and does not > agree with your stated result. > > On Wed, Dec 2, 2009 at 11:11 AM, Robert O'Boyle > <[email protected]>wrote: > > > > > > > > mask=. 0 1 1 1, 1 1 1 1 1, 0 0 0 0 0,: 1 1 1 1 0 > > > > [snip] > > > Which properly identifies the row entries but shifts row 0 to > the left by > > one. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
