title: How to apply defined functions to arrays in Python?
body: <p>I have two functions: <code>time_reversal</code> which reverses my time component "n" ; and  <code>time_shift</code>, which shifts my time coordinate "n" in a "k" quantity. These are the functions:</p>
  
  <pre><code>#time_reversal    
  
  def time_reversal(n):                              
          ind = arange(n.size-1,-1,-1)                   
          n_r=n[ind]                                     
          return n_r                                        
  # time_shift                                          
  def time_shift(n,k):                               
          N=n.size                                          
          if k&gt;=0:                                          
             N_ts=concatenate( (zeros(k),n[0:N-k]), 0)  
          else:                                              
             k=-k                                             
          N_ts=concatenate( (n[k:N],zeros(k)), 0)    
          return N_ts  
  </code></pre>
  
  <p>Given the equation : <code>y[n]=y[n]+x[k]*h[n-k]</code>
  I need to apply this equations to the "h" array. I need to reverse "n" and shift it a "k" quantity. The array "x" stays un touched. </p>
  
  <p>The problem is that I don't know how to apply those functions to my problem. I tried to substitute "n_r" and "N_ts" like this :<code>y[n]=y[n]+x[k]*h[n_r-N_ts]</code> but it gives me errors.
  EDIT :PROGRAM</p>
  
  <pre><code>from numpy import*
  from matplotlib.pyplot import*
  
  x=array([2,1,-1])
  h=array([1,2,1,0,1,2,1])
  y=array([0,0,0,0,0,0,0,0,0])
  
  def time_reversal(n):                              
          ind = arange(n.size-1,-1,-1)                   
          n_r=n[ind]                                     
          return n_r                                        
  
  def time_shift(n,k):                               
          N=n.size                                          
          if k&gt;=0:                                          
             N_ts=concatenate( (zeros(k),n[0:N-k]), 0)  
          else:                                              
             k=-k                                             
          N_ts=concatenate( (n[k:N],zeros(k)), 0)    
          return N_ts  
  
  for n in range(0,9):
       for k in range(0,3):                                       
          y[n]=y[n]+x[k]*h[n_r-N_ts]                         
  print("y = ",y)
  </code></pre>
  
  <p>It says that n_r and N_ts are not defined for some reason.</p>