Home > Mobile >  How to run a function against an array of inputs?
How to run a function against an array of inputs?

Time:10-08

How can I use numpy to generate an array of models by calling a function f()?

Say for example I have a list of values I want to use: z = [0,0.1,0.25]

Can run a function : f(x,y,z_i) where z_i is a variable in z?

I was thinking I can use something like arr = np.array(map(f(x,y,z),z) but I'm not sure how to relate the function inputs with the array I want to use.

CodePudding user response:

I like the expresiveness of a list comprehension

 np.array([f(x,y,zi) for zi in z])
  • Related