title: How to use a pair of nested for loops to iterate over a 2-d array?
body: <p>Need to take the values from one array, put them through a function and put them in another array. It is meant to be done using a pair of nested for loops. Please help. Complete beginner here.</p>
  
  <p>EDIT: Ok to clarify, I have a 2-d array with various values in it. I want to apply a function to all of these values and have a 2-d array returned with the values after they have gone through the function. I am working in python. Thanks for the quick responses and any help you can give!</p>
  
  <p>EDIT3: Example code:</p>
  
  <pre><code>import numpy as N
  
  def makeGrid(dim):
      ''' Function to return a grid of distances from the centre of an array.
      This version uses loops to fill the array and is thus slow.'''
      tabx = N.arange(dim) - float(dim/2.0) + 0.5
      taby = N.arange(dim) - float(dim/2.0) + 0.5
      grid = N.zeros((dim,dim), dtype='float')
      for y in range(dim):
          for x in range(dim):
              grid[y,x] = N.sqrt(tabx[x]**2 + taby[y]**2)
      return grid
  
  import math
  
  def BigGrid(dim):
      l= float(raw_input('Enter a value for lambda: '))
      p= float(raw_input('Enter a value for phi: '))
      a = makeGrid 
      b= N.zeros ((10,10),dtype=float) #Create an arry to take the returned values
      for i in range(10):
          for j in range (10):
              b[i,j] = a[i][j]*2
  
  
  if __name__ == "__main__":
      ''' Module test code '''
      size = 10 #Dimension of the array
      newGrid = BigGrid(size)
      newGrid = N.round(newGrid, decimals=2)
      print newGrid
  </code></pre>