Here, |. should be called three times, and for each call the left argument is a scalar and the right argument is a row or vector. This suggests using rank 0 1, and it turns out that works:
(-i.#M) |."0 1 M 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 Probably a better way to approach this is that you want to map over one axis on each side: the left argument has three things (atoms) and the right argument has three things (rows). A negative rank lets you specify how many leading axes the rank operator should go into: (-i.#M) |."_1 M 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 Rank _1 is probably the most common rank I use. The way I usually think about it is that it treats each argument as a list of its items (https://code.jsoftware.com/wiki/Vocabulary/Glossary#Item) and calls the function on every pair of items. Marshall On Sat, Mar 21, 2020 at 09:14:32AM +0000, Dimitri Georganas wrote: > Hi, > > I've been struggling to find an elegant way to shift each row i of a matrix > M by i to the right. > > 1 1 1 1 0 0 0 0 > 1 1 1 1 0 0 0 0 > 1 1 0 0 0 0 0 0 > > becomes > > 1 1 1 1 0 0 0 0 > 0 1 1 1 1 0 0 0 > 0 0 1 1 0 0 0 0 > > -(i.&#) M returns the vector, in this case, 0 _1 _2 > Now I want to apply 0 _1 _2 over each row of M as an argument to |. to get > something like 0 _1 _2 |. / M but obviously this doesn't work (I tried > several combinations with the correct rank). > > I'm sure this is not hard to do, but I got stuck and would appreciate your > help > > Best regards, > > Dimitri > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
