Skip to content Skip to sidebar Skip to footer

Numpy Resize Or Numpy Reshape

I've been scouring the stackexchange archives and can not seem to come across the right answer... should reshape be used, should resize be used, but both fail... setup: 3 netCDF fi

Solution 1:

Neither.

Reshape only changes the shape of the data, but not the total size, so you can for example reshape an array of shape 1x9 into one which is 3x3, but not into 2x4.

Resize does similar thing, but lets you increase the size, in which case it will fill new space with elements of array which is being resized.

You have two choices: write your function which does resizing in the manner you want it to do so, or use one of Python image libraries (PIL, Pillow...) to apply common image resizing functions.

Solution 2:

Did had the same problem:

  File "primes_test2audio.py", line 117, in<module>
  librosa.display.specshow(features.reshape(n_feat, n_frames) ,
  ValueError: cannot reshape arrayof size 9620into shape (20,313)

Answer : you divide by 9620/20=481 and you get a compatible shape:

  shape ofone sample in2D:  (20, 481)
  shape ofone sample flat: (9620,)

n_frames = 481 # number of frames for each sample

n_features = 20 # number of coefficients for mfcc analysis

Post a Comment for "Numpy Resize Or Numpy Reshape"