Yes, that's the normal way to do this.  You can also use

data -"1/ other

which is the same as

data -"1"1 _ other

giving result shape 4 2 4 (i. e. a transpose of what you got).


I use u"r1"r2 (two ranks) pretty often, three ranks very rarely, and have never had a use for four ranks.

Henry Rich

On 6/7/2017 4:12 AM, 'Jon Hough' via Programming wrote:
Assume I have a dataset of shape 4 4
data=: 4 4 $  i. 16

and some other data of shape 2 4 (i.e. same number of columns, different number 
of rows)

other=: 2 4 $ 100 200 130 250 2 4 6 8

I want to subtract each row of other from data, so that the result has shape  2 
4 4. i.e. I know the result of each row of
other subtracted from the whole of data.
The way I do this is:

data -"1 1"_ 1 other

For me, at least, chaining " is a new concept. I didn't know it was possible 
until relatively recently. I find it slightly ugly because, for me, it is very 
difficult to figure out how the ranks of the verb and the nouns all interact. But is 
this a J-esque way to
solve the above problem? Are there other ways to solve it?

Extra:
Because the above example is slightly contrived, I will just give a more 
concrete example. Suppose I have a dataset X, of shape A B,
and I have a collection, Y, of "average values" of other datasets, where the 
collection has shape C B, each row of Y being an average of
some dataset.
I want to know the values of the first dataset minus each average. So
X -"1 1"_ 1 Y gives this result, and it has shape C A B.

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


---
This email has been checked for viruses by AVG.
http://www.avg.com

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

Reply via email to