CSV to matrix array

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Apr 12 13:23:56 EDT 2013


----- Original Message -----
> Hello!
> 
> I have a CSV file with 20 rows and 12 columns and I need to store it
> as a matrix. I already created an array with zeros, but I don't know
> how to fill it with the data from the csv file. I have this script:
> 
> import numpy
> from numpy import array
> from array import *
> import csv
> 
> input = open('Cenarios.csv','r')
> cenario = csv.reader(input)
> 
> array=numpy.zeros([20, 12])
> 
> 
> I know I have to use for loops but I don't know how to use it to put
> the data the way I want. Can you help me?
> 
> Thanks!

did you try 

array = numpy.array(list(cenario))

?

JM



-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list