简体   繁体   中英

python normalize weird behaviour

I am trying to do training based on a set of sound samples. I would like to make the negative samples broader by normalising the positive samples.

This is my code :

for sound in dogbarks:
    expandedsound = audio_to_metadata(sound)
    preprocessed_dogbarks.append(expandedsound)
for sound in noisesounds:
    expandedsound = audio_to_metadata(sound)
    preprocessed_noisesounds.append(expandedsound)

labels = [0]*len(preprocessed_noisesounds) + 
[1]*len(preprocessed_dogbarks)
assert len(labels) == len(preprocessed_noisesounds) + 
len(preprocessed_dogbarks)
allsounds = preprocessed_noisesounds + preprocessed_dogbarks

allsounds_normalized = normalize(allsounds)

when the code try to normalise the set of array and it reaches the certain number of member in my case 48 it returns error :

~/.local/lib/python3.5/site-packages/sklearn/utils/validation.py in 
check_array(array, accept_sparse, dtype, order, copy, 
force_all_finite, ensure_2d, allow_nd, ensure_min_samples, 
ensure_min_features, warn_on_dtype, estimator)
    431                                       force_all_finite)
    432     else:
--> 433         array = np.array(array, dtype=dtype, order=order, copy=copy)
    434 
    435         if ensure_2d:
ValueError: setting an array element with a sequence.

However, If I run the member number 48 only it works fine. Can anyone give me a clue? I can provide the data if you would like to.

Thank you.

Since there is no easy solution for my question. I am taking the alternative way which loop and normalise it one by one and put it back to the array.

for sound in allsounds :
    allsounds_normalized.append(normalize([sound])[0])

Let me know if you guys have a better solution but for now, this is the solution. Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM