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


Groups > comp.lang.python > #43463

Re: CSV to matrix array

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'columns': 0.16; 'csv': 0.16; 'loops': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:CSV': 0.16; 'subject:array': 0.16; 'wrote:': 0.18; 'input': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'array': 0.29; "i'm": 0.30; 'url:wiki': 0.31; 'file': 0.32; 'me?': 0.32; 'thanks!': 0.32; 'url:python': 0.33; 'created': 0.35; 'but': 0.35; 'there': 0.35; 'url:org': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; "you're": 0.61; 'charset:windows-1252': 0.65; 'ana': 0.84; 'matrix.': 0.84; 'url:reference': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: CSV to matrix array
Date Fri, 12 Apr 2013 16:25:48 +0100
References <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-92-18-43-197.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
In-Reply-To <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com>
X-Antivirus avast! (VPS 130412-0, 12/04/2013), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.526.1365780304.3114.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365780305 news.xs4all.nl 2687 [2001:888:2000:d::a6]:53398
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43463

Show key headers only | 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