T
T
Timebird2016-02-14 22:29:40
Python
Timebird, 2016-02-14 22:29:40

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

2 answer(s)
N
nirvimel, 2016-02-14
@Timebird

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))]

O
Oscar Django, 2016-02-15
@winordie

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 question

Ask a Question

731 491 924 answers to any question