Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43463

Re: CSV to matrix array

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: CSV to matrix array
Date 2013-04-12 16:25 +0100
References <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.526.1365780304.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 07:22 -0700
  Re: CSV to matrix array Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-12 16:25 +0100
    Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:12 -0700
      Re: CSV to matrix array rusi <rustompmody@gmail.com> - 2013-04-12 10:34 -0700
    Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:12 -0700
  Re: CSV to matrix array Miki Tebeka <miki.tebeka@gmail.com> - 2013-04-12 16:10 -0700
  Re: CSV to matrix array giacomo boffi <pecore@pascolo.net> - 2013-04-13 14:06 +0200
    Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-13 08:30 -0700
      Re: CSV to matrix array Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-13 17:52 +0100
      Re: CSV to matrix array Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-13 20:01 +0100

csiph-web