[Numpy-discussion] computing average distance
Paul Rudin
paul at rudin.co.uk
Mon Nov 3 00:52:30 EST 2008
Gael Varoquaux <gael.varoquaux at normalesup.org> writes:
> Hey Emmanuelle, ( :>)
>
> On Sun, Nov 02, 2008 at 08:39:39PM +0100, Emmanuelle Gouillart wrote:
Thanks both of you.
> this will avoid what seems to be an error in Emmanuelle's answer. By
> the way, I am not too sure why Paul has used a numpy.array here. For
> this part of the code, it is not terribly usefull.
>
I'd used array because of what I do next. Having found the average
distance from the centre I want to scale the image so that the average
weight is about R/2, and then move the image so that it's centred around
the middle of the space. This is quite slow too...
scale_factor = (R/2)/av_dist
# scale so that our average distance from the centre is R/2
def transformer(point):
return tuple(((numpy.array(point) - centre) * scale_factor)
+ centre)
self.bits = scipy.ndimage.geometric_transform(self.bits, transformer)
# move so that we're centred in the middle of the voxelspace
self.bits = scipy.ndimage.shift(self.bits, midpoint-centre)
More information about the NumPy-Discussion
mailing list