title: Python: Normalize multidimensional array
body: <p>I have code to generate and export 12 stereo WAVs</p>
  
  <p>Currently I'm just doing:</p>
  
  <pre><code>for i in range(0,12):
      filename = "out_%d.wav" % i
      L = ... some list of floats between -1.0 and +1.0 ...
      R = ... similarly ...
  
      exportWAV(filename,L,R)
  </code></pre>
  
  <p>but the volumes are too quiet.</p>
  
  <p>What I need to do is find the maximum volume across all L &amp; R, and divide all L &amp; R by this volume. Then all of my values will be between -1 and 1.</p>
  
  <p>It isn't a difficult task, and I can hack out some ugly code to get it done.</p>
  
  <p>But how to do it cleanly?</p>
  
  <p>I should be able to do it in just a few lines, something like:</p>
  
  <pre><code>all_LR = ''
  all_file = ''
  
  for i in range(0,12):
      filename = ...
      L, R = ...
  
      all_LR += (L,R)
      all_file += filename
  
  maxVal = max( abs(all_LR) )
  all_LR /= maxVal
  
  for file,L,R in zip( all_file, all_LR ):
      exportWAV(filename L,R)
  </code></pre>
  
  <p>But I can't see how to turn this pseudocode into actual valid Python.  abs and max don't operate over an array of tuples where each element in the tuple is itself an array of floats.</p>
  
  <p>I feel like I'm making it more difficult than it needs to be just by trying to save a few lines of code.</p>
  
  <p>EDIT: thanks to the below answer I now have the following working code:</p>
  
  <pre><code>all_LR = []
  
  for i in range(0,12):
      print "Processing %d" % i
  
      hrtf_file = hrtf_path + "/%02d.wav" % (i+1)
      shep_file = shepard_path + "/shepard_%02d.WAV" % i
  
      L, R = import_WAV( hrtf_file )
      shep = import_WAV( shep_file )
  
      out_L = np.convolve(shep,L)
      out_R = np.convolve(shep,R)
  
      #out_LR = np.array( out_L, out_R )
      out_LR = (list(out_L), list(out_R))
      all_LR.append(out_LR)
      #np.append( all_LR, out_LR )
  
  np_array = np.array(all_LR)
  
  amp_max = np.amax( np.fabs(np_array) )
  print( "AmpMAX: %f" % amp_max )
  
  np_array /= amp_max
  
  for i in range(0,12):
      out_file = out3d_path + "/s3D_%02d.WAV" % i
      print out_file
  
      L,R = np_array[i]
  
      export_WAV( out_file, L, R )
  </code></pre>