slice assignment: strange behaviour

koara koara at atlas.cz
Wed Nov 8 17:36:33 EST 2006


Hello,

a piece of my code started giving strange results with certain data; i
managed to track down the cause to a slice array assignment. In the
following code snip; 'mat' is a numpy.array with shape=(22973, 1009),
'vec' is a numpy.array with shape=(22973,), both of type int:

for i in xrange(1009):
    ...
    fr = vec[10001]
    mat[:, i] = vec # assign whole column
    if mat[10001, i] != fr:
        print "how come?"
     ...

for elements beyond index 10000, nothing is assigned (ie,
numpy.sum(mat[row, :]) is zero for any row > 10000). As soon as i
replace the assignment with a cycle that assigns each element
explicitly (for j in xrange(22973): result[j, i] = vec[j]),
everything's OK. With some matrices, the above seems to work fine
though, as well as for smaller dimensions, so i am unable to provide a
full simple example.

Any ideas? I am using enthought python (python 2.4.3) which uses numpy
version 0.9.9.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list