I have numpy array mfcc having mfcc values , and is of shape (5911,20).
I have one list a =[] which has 5911 labels like apple cow dog.
I want to append the these labels to the mfcc numpy array.
STEP1 I converted list with labels to an array :
at = np.array(a)
print (at)
print at.shape
print type(at)
['apple' 'apple' 'apple' ..., 'cow' 'cow' 'cow']
(5912,)
<type 'numpy.ndarray'>
STEP2 I made sure both at and mfcc were of same dimensions:
if len(at) > len(mfcc):
at= at[ :-1]
STEP3 Then I stacked them together.
mfcc_with_labels=np.hstack((mfcc_with_labels,at[:,None]))
print mfcc_with_labels.shape
(5911,21)
PROBLEM STEP Now I want to save this mfcc_with_labels to a file. So that I can feed it to a neural network later.
np.savetxt("mfcc_with_labels.txt", mfcc, newline= "\n", delimiter="/t")
and it throws a huge ERROR **
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-7709c644ca06> in <module>()
1 print mfcc_features_with_times_and_labels.shape
2
----> 3 np.savetxt("mfcc_with_labels.txt", mfcc, newline= "\n", delimiter="/t")
/usr/local/lib/python2.7/dist-packages/numpy/lib/npyio.pyc in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments)
1256 raise TypeError("Mismatch between array dtype ('%s') and "
1257 "format specifier ('%s')"
-> 1258 % (str(X.dtype), format))
1259 if len(footer) > 0:
1260 footer = footer.replace('\n', '\n' + comments)
TypeError: Mismatch between array dtype ('|S32') and format specifier ('%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e/t%.18e')
**
I tried specifying 'fmt = %s' as an option but nothing happens.
I inspected and
mfcc_with_labels[1] and the stacking/appending did work,
['-498.357912575' '-3.40930872496e-14' '1.55285010312e-14' '-5.31554105812e-14' '4.81736993039e-15' '-3.17281148841e-14' '5.24276966145e-15' '-3.58849635039e-14' '3.11248820963e-14' '-6.31521494552e-15' '1.96551267563e-14' '1.26848188878e-14' '6.53784651891e-14' '-3.15089835366e-14' '2.84134910594e-14' '1.03625144071e-13' '-5.52444866686e-14' '-5.04415946628e-14' '1.9026074286e-14' '3.42584334296e-14' 'apple']
Unable to comprehend why it is not being saved.
I already looked at : numpy beginner: writing an array using numpy.savetxt numpy savetxt fails when using file handler How to combine a numpy array and a text column and export to csv
Please guide me how to save this new numpy array properly. I'm from an R programming background, in python is there any easy of python equivalent of saving this array like an R data frame kind of structure?
Final goal is to send this into a neural network.
I tried specifying 'fmt = %s' as an option but nothing happens.That's awfully vague. No error message? No file output? Are you sure you are looking in the right place for that file?