CSV to matrix array
Mark Lawrence
breamoreboy at yahoo.co.uk
Fri Apr 12 11:25:48 EDT 2013
On 12/04/2013 15:22, Ana Dionísio wrote:
> 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!
>
I'm no expert on numpy but there is a loadtxt function see
http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
More information about the Python-list
mailing list