Generally speaking, tensor products may sum along "the diagonal" combining a variable number of pairs of axes (axises?).
For outer product, that number is zero. For matrix product, that number is one. For the general case, that number might be higher. As for your one liner, it looks like you're using the wrong form of the } conjunction. To accomplish what you want, you should be using the form u1`u2`u3} where u1 computes the x value for the merge, u3 computes the y value for the merge, and u2 computes the m value for the merge. In other words: 1:`(|:@((],[)$i.@[))`(([$])$0:)} Or, more concisely: 1:`(#"1 i.@,&1)`(0$~$)}~ I hope this helps, -- Raul On Mon, Jun 28, 2021 at 6:40 PM 'Viktor Grigorov' via Programming <[email protected]> wrote: > > Nabble-fora are in a sickly state, refusing full perusal, so excuse me if > this's been answered.. > I wanted an x-dimensional y-rank identity matrix. > > With an auxilliary verb to get a main diagonal from an > arbitrarily-dimensional square array verb: > > md=: (|:~(<@i.@#@$)) > > I assured the following verb yields 1s in the main diagonal and 0s elsewhere: > > id=: 4 : 0 > q=.x(|:@(([,])$i.@]))y > x (1 q}([$])$0:) y > ) > > I still do not understand why the below one-liner doesn't suffice, given all > individual parts work as intended. Substituting the 1 for, say, a 2 or 9, > results in that many filled elements in the first face with that same number > (1 1, 2 2s, 9 9s, etc.). > > (1 (|:@((],[)$i.@[)) }([$])$0:) > > Anyways, I was immediate struck down, discovering that (+/ .*) doesn't > exactly work for >2-dimensional arrays, because of the recursive minor-based > action of the dot product, making increasingly ranked array spit out more and > more dimensioned results. Worse still, discussing matrix multiplication with > two colleagues, I more or less got 'oddly-dimensioned tensor products are > iffy'. > I was told to first define the multiplication, which would then yield the > identity matrix, as opposed to what I did- extending the 2D cased. > I'll be looking through some multilinear algebra in my spare time, but I was > wondering if there's an accepted way in J )or the other APL family language) > for multidimensional multiplication, or if it's best decided on a case by > case basis. > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
