Search code examples
j

How to calculate by rows in J


For example, there are two 164*90 matrixes and a function.

beta=: 4 : 0
a=. x cor y
b=. sd x
c=. sd y
a*b%c
)

I want to use each row of matrix 1 and each row of matrix 2 into the function. How can I do it at once?


Solution

  • beta=: 4 : 0"1
    a=. x cor y
    b=. sd x
    c=. sd y
    a*b%c
    )
    

    The "1 after the 0 in the definition above makes your verb rank 1 which means that it would take whatever matrices it is given a row at a time. An alternative would be to call your originally defined verb with rank "1

    x beta"1 y