numpy - Python: Normalize multidimensional array -


I have code to create and export 12 stereo WAVs

I'm just doing this :

  for i category (0,12): filename = "out_% d.wav"% il = ... list of float between some -1 and +1.0 .. R =. ..so ... exportWAV (file name, L, R)   

but the volume is very quiet.

What do I need to do to maximize all L & amp; R, and all L & amp; By this quantity r. Then all my values ​​will be between -1 and 1.

This is not a difficult task, and I can exclude some ugly code to do this.

But how to do it properly?

I should be able to do this in just a few lines:

  all_LR = '' all_file = '' i (0,12): file name = .. L, R = ... all_LR + = (L, R) all_file + = filename maxVal = max (abs (all_LR)) for all_LR / = maxVal file, zip in L, R (all_file, all_LR): exportWAV File name l, r)   

But I can not see how to turn this pseudocode into actual valid Python. Abs and Max do not work on an array of Tuples, where each element in the tuple is an array of float itself.

I think I'm making it more difficult because it is trying to save some lines of code.

EDIT: Thanks for the answers given below I have the following working code:

  all_LR = [] for category i (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)) SHAP = import_WAV (Shape_file) out_l = np.convolve (shape, l) out_r = np.convolve (shape, r) #out_lR = np (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. In the category for the fabs (np_array) print ("AmpMAX:% f"% amp_max) np_array / = amp_max (0,12): out_file = out3d_path + "/s3D_%02d.WAV"%I print out_file L, R = Np_rere [i] export_WAV (out_file, L, R)    

Can be converted to numpy.arrays so you can use and down as the.

  Import numpy as NP A = NP Array ([(1, 2), (-3, 4), (-2, 2), (0, 1), (1, 3)]) a_abs = np.fabs (a) Print (a_abs) # [ [1. 2.] # [3. 4] # [2. 2.] # [0] 1] # [1. 3.]] a_max = np.amax (a_abs) print (a_max) # 4.0   

np.fabs will return an array of only one size, but one With the full value of each element in multi-dimensional array.

np.amax will return the maximum value of an array. If you select a axis by using a keyword-logic (like np.amax (a, axis = 0) ), then it will be axis / . There is no default any for axis keywords, due to which it will work on flat alignment.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -