Saving full array as txt in python
<p>I at the moment trying to sample an audio files and store the information from the sampling into to txt file. </p>

<p>The sampling is done using the <a href="https://github.com/librosa/librosa" rel="nofollow">librosa</a>. </p>

<p>The problem occurs when i save  it to a file... 
The array doesn't get fully saved, I am only able to view a few of the sampling point, and the rest is dotted. </p>

<p>example: </p>

<pre><code>22050.000
[ -8.61534572e-05  -1.64340396e-04  -8.03423245e-05 ...,  -1.40137578e-04
  -3.71412549e-04  -5.04361582e-04]  
</code></pre>

<p>This is how i am doing it:</p>

<pre><code>import tensorflow as tf
import numpy as np
import librosa
from os import listdir
from os.path import isfile, join
import os



path_train =  "/home/k/kaldi-trunk/egs/start/s5/data/train"
path_test =  "/home/k/kaldi-trunk/egs/start/s5/data/test"
dnn_train = "/home/k/kaldi-trunk/dnn/train/"
dnn_test = "/home/k/kaldi-trunk/dnn/test/"
dnn = "/home/k/kaldi-trunk/dnn/"
path  = "/home/k/kaldi-trunk/egs/start/s5/data/"
train_filelist = path_train+"/wav_train.txt"
test_filelist = path_test+"/wav_test.txt"

    files_train = [f for f in listdir(dnn_train) if isfile(join(dnn_train, f))]
    files_test = [f for f in listdir(dnn_test) if isfile(join(dnn_test, f))]

    os.chdir(dnn_train)
    train = []
    test  = []


    for line in files_train:
        #print dnn_train+line
        y,sr=librosa.core.load(dnn_train+line)
        train.append(y.tolist())

    print "Train done!"

    for line in files_test:
        x,sr=librosa.core.load(dnn_test+line)
        test.append(x.tolist())

    print "Test done!"

    os.chdir(dnn)

    with open('sample_test.txt','wb') as f:
        np.savetxt(f,test)

    with open('sample_train.txt','wb') as f:
        np.savetxt(f,train)
</code></pre>

<p>anything that could explain why i can't save all the sample point rather than a few?</p>

<p>desired output is two seperate files [sample_test,sample_train]
in which each line contain a list. 
each entry in the list should contain as many decimals, which is why either it would be appreciated having it stored as either float or double. </p>

<p>The argument to <code>np.savetxt</code> should be an array.</p>

<p>Add <code>test = np.array(test)</code> before saving the data.</p>

<ol>
<li>This will give an error if the data can not be converted to an array.</li>
<li>You can print, for diagnosis, the shape of the array: <code>print test.shape</code></li>
</ol>

<p>Your output suggests that you have a float and then a list in your data, that are printed instead of the content of a NumPy array.</p>

python numpy librosa