[newbie] confusion concerning fetching an element in a 2d-array
Jean Dubois
jeandubois314 at gmail.com
Tue Mar 25 06:26:26 EDT 2014
I'm confused by the behaviour of the following python-script I wrote:
#!/usr/bin/env python
#I first made a data file 'test.dat' with the following content
#1.0 2 3
#4 5 6.0
#7 8 9
import numpy as np
lines=[line.strip() for line in open('test.dat')]
#convert lines-list to numpy-array
array_lines=np.array(lines)
#fetch element at 2nd row, 2nd column:
print array_lines[1, 1]
When running the script I always get the following error:
IndexError: invalid index
Can anyone here explain me what I am doing wrong and how to fix it?
thanks in advance
jean
More information about the Python-list
mailing list