[Jprogramming] Verb Rank Misunderstandings with "

'Jon Hough' via Programming programming at jsoftware.com
Wed Jun 7 08:12:58 UTC 2017


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


More information about the Programming mailing list