X-Received: by 10.13.223.146 with SMTP id i140mr5851348ywe.37.1448102518447; Sat, 21 Nov 2015 02:41:58 -0800 (PST) X-Received: by 10.50.57.84 with SMTP id g20mr163553igq.3.1448102518420; Sat, 21 Nov 2015 02:41:58 -0800 (PST) Path: csiph.com!xmission!news.glorb.com!b51no1162714qgf.0!news-out.google.com!l1ni4434igd.0!nntp.google.com!mv3no107730igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Sat, 21 Nov 2015 02:41:57 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.150.246.108; posting-account=yqtuEQoAAABwgqN6njReXW6C0cndsij_ NNTP-Posting-Host: 85.150.246.108 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2141d7ae-1064-49f3-bf36-ff663fca0ffc@googlegroups.com> Subject: Problem to read from array From: vostrushka@gmail.com Injection-Date: Sat, 21 Nov 2015 10:41:58 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:99203 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