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


Groups > comp.lang.python > #43472

Re: CSV to matrix array

Date 2013-04-12 19:23 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: CSV to matrix array
Newsgroups comp.lang.python
Message-ID <mailman.530.1365787506.3114.python-list@python.org> (permalink)

Show all headers | View raw


----- 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.

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


Thread

Re: CSV to matrix array Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-04-12 19:23 +0200
  Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:29 -0700
    Re: CSV to matrix array Dave Angel <davea@davea.name> - 2013-04-12 13:46 -0400
    Re: CSV to matrix array Javier Miranda <javier@codecoa.com> - 2013-04-12 17:45 -0500
    Re: CSV to matrix array cantorp@gmail.com - 2013-04-13 10:06 -0700
    Re: CSV to matrix array cantorp@gmail.com - 2013-04-13 10:06 -0700
  Re: CSV to matrix array Ana Dionísio <anadionisio257@gmail.com> - 2013-04-12 10:29 -0700

csiph-web