[Numpy-discussion] Array assignment problem
Dinesh B Vadhia
dineshbvadhia@hotmail....
Tue Mar 11 16:44:56 CDT 2008
Hello! I'm reading a text file with two numbers in str format on each line. The numbers are converted into integers. Each integer is then assigned to a 2-dimensional array ij (see code below). The problem is that neither of the array assignments work ie. both ij[index, 0] = r and ij[index, 1] = c are always 0 (zero). I've checked r and c and both are integers (>=0).
import sys
import os
import numpy
nnz = 1200000
ij = numpy.array(numpy.empty((nnz, 2), dtype=int))
index = 0
filename = 'test_ij.txt'
for line in open(filename, 'r'):
line = line.rstrip('\n')
r, c = map(str, line.split(','))
r = int(r)
c = int(c)
ij[index, 0] = r
ij[index, 1] = c
index = index + 1
What am I doing wrong?
Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080311/1f639598/attachment.html
More information about the Numpy-discussion
mailing list