Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying multiple functions to each line of the input

Tags:

j

I have 2 normalization functions: norm1 and norm2.

norm1 =: (- <./) % >./ - <./
norm2 =: %(>./@:|) 

I want to apply these two functions to each line of the following input like this:

input123 =: i. 2 10

|:(norm1 0{input123),.(norm2 1{input123)

0 0.111111 0.222222 0.333333 0.444444 0.555556 0.666667 0.777778 0.888889 1
0.526316 0.578947 0.631579 0.684211 0.736842 0.789474 0.842105 0.894737 0.947368 1

Instead of using { to extract each line from the input123, is there any simpler way to apply multiple verbs to each line of an input array? Maybe by making an array of verbs and apply them to each line of the input?

It doesn't have to be a line, it can be each element("0), or matrix("2) for a higher-dimensional input data, etc

Thank you for your advice in advance. = ]

like image 974
Kevin Choi Avatar asked Jul 04 '20 06:07

Kevin Choi


1 Answers

You can actually do exactly what you'd like to do with a cyclic gerund:

   norm1`norm2"1 input123
       0 0.111111 0.222222 0.333333 0.444444 0.555556 0.666667 0.777778 0.888889 1
0.526316 0.578947 0.631579 0.684211 0.736842 0.789474 0.842105 0.894737 0.947368 1
like image 129
Julian Fondren Avatar answered Oct 07 '22 17:10

Julian Fondren