Thursday, September 9, 2010

Multidimensional find in pylab/numpy/matplotlib

A = pylab.random((3,3))
print A
idx = pylab.find(A < .5) #Returns an unravelled index
A.flat[idx] = .5 #allows us to use this flat index directly
print(A) #and it works just fine

No comments:

Post a Comment