title: Using lambda function to find element from another list or array
body: <p><strong>Edited the Question for Clarification</strong></p>
  
  <pre><code>import numpy as np
  tt = np.arange(0, 1000, 1)
  st = np.arange(0, 10, 1)
  def abc():
      return lambda x: st[np.where(tt==x)] if (50 &lt; x &lt;100) else 0
  print(abc()(tt))
  </code></pre>
  
  <p>Expectation is that for a given, long <strong>periodic</strong> time-series <strong>tt</strong> with a period of <strong>100</strong>, the function abc() should output the values in <strong>st</strong> for the interval 50-100, 150-200, 250-300, and spit out 0 elsewhere. Something like..</p>
  
  <pre><code>[0....0..st.....st.0.....0.st....st.0....0.st.....st]
  </code></pre>
  
  <hr>
  
  <p><strong>Previously asked....</strong></p>
  
  <p>I inherited a long code to which I need to do some modification. The basic format is a number of functions, each returning a lambda function</p>
  
  <pre><code>def func1():
    return lambda x: #some math with x, like x**2
  
  def func2():
    return lambda x: #some math with x, like np.sin(x)
  </code></pre>
  
  <p>and so on..</p>
  
  <p>These functions are supplied with a time-series, t, a numpy 1D array from which the required math function is generated. It works properly.</p>
  
  <p>For instance</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  t = np.arange(0, 100, 1)
  
  def fun1():
    return lambda x: x**2
  
  print(fun1()(t)) 
  plt.plot(t, fun1()(t))
  plt.savefig('Graph.png')
  </code></pre>
  
  <p>Now I wish to import/read data from an external file as a [time, value] pair and use that to generate the new math function, instead of doing math in the function itself as before.</p>
  
  <p>After reading from a file, I have say,</p>
  
  <pre><code>time = [0, 0.1, 0.2, ..... 1000.0]
  value = [v1, v2, ...........vn]
  </code></pre>
  
  <p>I want to do</p>
  
  <pre><code>def new_func():
     return lambda x: "*Looking for an answer*"
  </code></pre>
  
  <p>So that if I call <strong>new_func</strong>()(t), I get the <strong>value</strong> as the output</p>
  
  <p>I have tried np.where, and tried defining subfuctions. But nothing has worked so far. Because I have to pass this function to another code, I can't change the basic format. Please advise.</p>