Hello forum,

currently I try to make use of the Fold family of primitives to achieve a rather simple (I think) task. However, I have not been able to reach the desired goal. This is, what I want to do:

Suppose, I have some matrix M and some vector V:

M =: 3 4 $ 12?12
V =: 1 2 3

I now want to apply each element of V to the whole of M (an operation which is supposed to give a result with the same size of M). I want to give a short exemplary demonstration of the data flow I imagine:

M => Start
7 4 11 3
0 1 6  10
9 2 5  8

M1 => (M e. 0 { V)
0 0 0 0
0 1 0 0
0 0 0 0

M2 => (M e. 1 { V)
0 0 0 0
0 0 0 0
0 1 0 0

M3 => (M e. 2 { V)
0 0 0 1
0 0 0 0
0 0 0 0

Result => M1 + M2 + M3
0 0 0 1
0 1 0 0
0 1 0 0

To me it seems, that this would be a task for the Fold family of primitives, but I don’t seem to be able to get my head around this. I’d very much appreciate any hints on how to implement this with Fold - and of course I’d like to know, whether my intuition, that the Fold family would be the right tool for the job, is right or if there are better options.

Happy holidays to everyone and kind regards,

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

Reply via email to