3

I have a np array with 1000 rows, and 4608 columns each rows

I try to save a csv file with:

myfile = open('dataset.csv', 'wb')
wr = csv.writer(myfile,delimiter='\n')
wr.writerow(Prueba[0])

But if I open the csv file with LibreOffice this:

[153 147 147 ..., 142 147 146]  
[183 247 147 ..., 126 123 104]
...

No apears the 4608 columns!!

Some idea?

Thank you!

Regards, Andres.

2 Answers 2

8

Try this.

numpy.savetxt("FILENAME.csv", a, delimiter=",")

Where filename is your filename and a is your array.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Jeremy, but This return the next error: TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')
If all numbers are int, you can add the option fmt='%d'
Thanks Julien. All numbers are type <type 'numpy.uint8'>, I try its in then: TypeError: Mismatch between array dtype ('object') and format specifier ('%d')
1

The type of the array and the fmt option must match. Try:

import numpy as np

np.savetxt('dataset.csv', array.astype(np.int), fmt='%d', delimiter=',')

where array is your numpy array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.