Answer the question
In order to leave comments, you need to log in
How to substitute an array into a function?
Hello, the question is as follows:
there are 4 variables containing 4 one-dimensional arrays with values.
You need to substitute them into the function, thereby getting one array of values at the output.
For example, let's take this function:
x(t) = a*sin(omega*t + phi)
Here a , omega , phi and t are the 4 known one-dimensional arrays.
Can you tell me how to syntactically get an array x as output?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
def f(a, omega, phi, t):
return a * sin(omega * t + phi)
x = [f(a[i], omega[i], phi[i], t[i]) for i in range(len(a))]
By request in addition to @nirvimel
Add sugar
And more
For simple functions
x = map(lambda a, omega, phi, t: a * sin(omega * t + phi), a, omega, phi, t)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question