apply 2 functions to 2xN matrix

q)x:((“0”;“zero”);(“1”;“one”);(“2”;“two”))

q)(-7h$;`$)@'/:x

((0;zero);(1;one);(2;`two))

is there a ‘functional’ way to do this (that might be faster)?

ta, jack

Hi Jack,

If the inputs are both string lists you could apply the function piece-wise, it’s about 50% faster than using two adverbs

“JS”$/:x

something to think about if your list is bigger, which usually is the case…

q)\ts:1000 “JS”$/:x

1 464

q)\ts:1000 flip"JS"$ flip x

1 672

q)\ts:1000 flip .Q.V update"J"$x,`$x1 from (x[;0];x[;1])

7 2416

q)y:flip (string til n;3?'n#enlist .Q.a)   //make a list longer than x

q)\ts:10 “JS”$/:y

4978 72388816

q)\ts:10 flip “JS”$flip y

3109 89166064

q)q)\ts:10 “JS”$flip y   //note the memory difference from using a second flip as above - 2.65x less plus speedup.

2270 33554688

q)\ts:10 flip value .Q.V update"J"$x,`$x1 from (y[;0];y[;1])

2992 89166800

q)\ts:10 value .Q.V update"J"$x,`$x1 from (y[;0];y[;1])

2154 33555696

q)(flip value .Q.V update"J"$x,`$x1 from (y[;0];y[;1]))~“JS”$/:y

1b

HTH,

Sean

Hey Jack,

As Kevin said “JS”$/:x works well.

Just to add that if your elements repeat then .Q.fu might help speed things along

x:100000?((“0”;“zero”);(“1”;“one”);(“2”;“two”);(“0”;“zero”);(“5”;“five”))

\ts m:.Q.fu[{“JS”$/:x};x]

14 5243472

\ts n:“JS”$/:x

26 7448896

m~n

1b