[Numpy-discussion] array indexing question
Catherine Moroney
Catherine.M.Moroney@jpl.nasa....
Thu Nov 13 23:47:03 CST 2008
Hello,
I know that there must be a fast way of solving this problem, but I
don't know
what it is.
I have three arrays, with dimensions:
A[np]
L[np]
S[np]
where L and S indicate the line, smp co-ordinates for each of the
"np" rows.
I want to reconstruct the contents of [A] as a 2-dimensional matrix.
The brain-dead version of what I want is:
results = numpy.zeros(some_size, some_other_size)
for idata in xrange(0,np):
results[L[idata], S[idata]] = A[idata]
but I'm dealing with large arrays and this is very slow. How
do I speed it up? The array A is the result of performing kmeans
clustering on a large 2-d image, presented as a 1-d vector and I
want the result as a 2-d image.
In the real application, I won't have data for each point in the 2-d
image, so np will be less than the full image size.
Catherine
More information about the Numpy-discussion
mailing list