[SciPy-user] stupid array tricks

Karl Young karl.young@ucsf....
Fri Feb 6 16:08:01 CST 2009

I know there are a number of array manipulation maestros on the list and 
wanted to run a problem by the list that my feeble mind  is foundering on.

I have three objects, 1) an array containing an "image" (could be any 
dimension), 2) a mask for the image (of the same dimensions as the 
image), and 3) a "template" which is just a list of offset coordinates 
from any point in the image.

Say the template has n elements, the problem is to move the template 
over the image and build an m x n array containing image values (at the 
template positions) where m is the number of image indices such that the 
template lies within the image and all mask values are true. I currently 
do this using some raveling, compressing, and length comparison but I 
still haven't been able to figure out how to do it without looping 
through the image indices (and this is sloooowwww for big 
multidimensional "images"). I keep feeling like there must be some 
clever way to concatenate the template with the image and mask so as to 
do this without looping but haven't been able to come up with it. I 
could speed it up by doing the looping in C but that doesn't seem very 
elegant. Any thoughts welcome.


More information about the SciPy-user mailing list