Valueerror: Could Not Broadcast Input Array From Shape (20,590) Into Shape (20)
I am trying to extract features from .wav files by using MFCC's of the sound files. I am getting an error when I try to convert my list of MFCC's to a numpy array. I am quite sure
Solution 1:
Use the following logic to downsample the arrays to min_shape
i.e. reduce larger arrays to min_shape
min_shape = (20, 345)
MFCCs = [arr1, arr2, arr3, ...]
for idx, arr in enumerate(MFCCs):
MFCCs[idx] = arr[:, :min_shape[1]]
batch_arr = np.array(MFCCs)
And then you can stack these arrays in a batch array as in the below minimal example:
In [33]: a1 = np.random.randn(2, 3)
In [34]: a2 = np.random.randn(2, 5)
In [35]: a3 = np.random.randn(2, 10)
In [36]: MFCCs = [a1, a2, a3]
In [37]: min_shape = (2, 2)
In [38]: for idx, arr in enumerate(MFCCs):
...: MFCCs[idx] = arr[:, :min_shape[1]]
...:
In [42]: batch_arr = np.array(MFCCs)
In [43]: batch_arr.shape
Out[43]: (3, 2, 2)
Now for the second strategy, to upsample the arrays smaller arrays to max_shape
, follow similar logic but fill the missing values with either zeros or nan
values as you prefer.
And then again, you can stack the arrays as a batch array of shape (num_arrays, dim1, dim2)
; So, for your case, the shape should be (num_wav_files, 20, max_column
)
Post a Comment for "Valueerror: Could Not Broadcast Input Array From Shape (20,590) Into Shape (20)"