[SciPy-User] Numpy/Scipy: Avoiding nested loops to operate on matrix-valued images
tyldurd
dhondt.olivier@gmail....
Thu Mar 15 03:59:28 CDT 2012
Hello,
I am a beginner at python and numpy and I need to compute the matrix
logarithm for each "pixel" (i.e. x,y position) of a matrix-valued image of
dimension MxNx3x3. 3x3 is the dimensions of the matrix at each pixel.
The function I have written so far is the following:
def logm_img(im):
from scipy import linalg
dimx = im.shape[0]
dimy = im.shape[1]
res = zeros_like(im)
for x in range(dimx):
for y in range(dimy):
res[x, y, :, :] = linalg.logm(asmatrix(im[x,y,:,:]))
return res
Is it ok? Is there a way to avoid the two nested loops ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120315/b488c9c5/attachment-0001.html
More information about the SciPy-User
mailing list