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


Groups > comp.lang.python > #99203

Problem to read from array

Newsgroups comp.lang.python
Date 2015-11-21 02:41 -0800
Message-ID <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> (permalink)
Subject Problem to read from array
From vostrushka@gmail.com

Show all headers | View raw


Hi,
I have a file with one parameter per line:
a1
b1
c1
a2
b2
c2
a3
b3
c3
...
The parameters are lines of characters (not numbers)

I need to load it to 2D array for further manipulations.
So far I managed to upload this file into 1D array:

ParametersRaw = []
with open(file1) as fh:
    ParametersRaw = fh.readlines()
fh.close()

NumberOfColumns = 7
NumberOfRows = len(ParametersRaw)/NumberOfColumns

Parameters = [[],[]]
i=0
j=0
k=0
while (i < NumberOfRows):
    while (j < NumberOfColumns):
        k = (i*NumberOfColumns)+j
        Parameters[i][j] = ParametersRaw[k]
        j = j + 1
    i = i + 1
    j = 0

it fails at the line "Parameters[i][j] = ParametersRaw[k]" with error:

IndexError: index 0 is out of bounds for axis 0 with size 0

In case of populating 1D array I would use append() method.
But in case of 2D I am lost of how append() can be applied.
Could some one help newbie.

CU

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


Thread

Problem to read from array vostrushka@gmail.com - 2015-11-21 02:41 -0800
  Re: Problem to read from array Peter Otten <__peter__@web.de> - 2015-11-21 12:23 +0100
  Re: Problem to read from array Laura Creighton <lac@openend.se> - 2015-11-21 15:22 +0100
  Re: Problem to read from array Laura Creighton <lac@openend.se> - 2015-11-21 16:05 +0100
  Re: Problem to read from array BartC <bc@freeuk.com> - 2015-11-21 15:26 +0000
    Re: Problem to read from array Nathan Hilterbrand <nhilterbrand@gmail.com> - 2015-11-21 10:52 -0500
      Re: Problem to read from array Crane Ugly <vostrushka@gmail.com> - 2015-11-23 12:58 -0800
        Re: Problem to read from array sohcahtoa82@gmail.com - 2015-11-23 16:44 -0800
          Re: Problem to read from array Crane Ugly <vostrushka@gmail.com> - 2015-11-24 00:56 -0800
            Re: Problem to read from array Peter Otten <__peter__@web.de> - 2015-11-24 10:31 +0100

csiph-web