title: How to normalize values from a matrix in Python?
body: <p>I have created signals with noise in python code. I have stored them in an array - new_array with size(10,17,199,1). Index 0 represents the range of frequencies that are utilised to create the signal, index 1 represents the amplitude created by that frequency with different added noise (ranging from a standard deviation from 0.5 to 2.2 with increments of 0.1), index 2 and 3 represents the time domain i.e. the length of the array.</p>
  <p>Currently, this is what I'm producing when normalizing ...</p>
  <p><a href="https://i.stack.imgur.com/vCLTl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vCLTl.png" alt="enter image description here" /></a>.      <a href="https://i.stack.imgur.com/4XyzH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4XyzH.png" alt="enter image description here" /></a></p>
  <p>My question is how I can normalize the signal? When I use preprocessing.normalize the signal isnt what I'm expecting. Does anyone have any idea? I have posted my code below.</p>
  <pre><code>import numpy as np 
  from sklearn import preprocessing
  
  
  def frequency_labels(s_frequency):
      L = []
      for w, f2 in enumerate(s_frequency):
          l = &quot; {} Hz&quot;.format(f2)
          print(&quot;f1=&quot;,f2)
          L.append(l)
      return L
  
  def time_labels(time):
      H = []
      for r,t in enumerate(time):
          h = &quot; {} s&quot;.format(t)
          H.append(h)
      return H
  
  def gaussian_noise(increment,len_time):
      mean = 0
      standard_deviation = np.arange(0.5,2.2,increment) 
      ## want 8096 different noise signals of different standard deviations
      sd = standard_deviation.reshape(len(standard_deviation),1)
      noise = np.empty((len(sd), (len_time), (1)), dtype=np.float16)
       
      for t, value in enumerate(sd):
           
          noise[t] = np.random.normal(mean,value,len_time).reshape(len_time,1)
          
      return(noise)
  
  
  max_freq = 50
  s_frequency = np.arange(20,30,1) # range of frequencies
  fs = 200
  time = np.arange(0,2-(1/fs),(1/fs))
  amplitude = np.empty((len(time)), dtype=np.float16)
  len_time = len(time)
  len_frequency = len(s_frequency)
  array = np.empty((len(time)), dtype=np.float16)
  increment = 0.1  #0.00021
  L = frequency_labels(s_frequency)
  H = time_labels(time)
  k = 0 
  noise = gaussian_noise(increment,len_time)
  new_array = np.empty((len(s_frequency),(len(noise)),len(time),(1)),dtype=np.float16)
  
  for f1 in s_frequency:
  
      
      for i, t in enumerate(time):
         
        amplitude[i] = np.sin(2*np.pi*f1*t)
             
      amplitude = amplitude.reshape(len(time),1)
      #n_amplitude = preprocessing.normalize(amplitude)
      new_array[k] = np.add(noise,amplitude)
  
      for r in range(17):
          new_array[k,r,:,:] = preprocessing.normalize(new_array[k,r,:,:])
          
      k = k + 1
  </code></pre>