2 Nov
2008
2 Nov
'08
7:23 p.m.
I'm experimenting with numpy and I've just written the code below, which computes the thing I want (I think). Self.bits is an RxRxR array representing a voxelized 3d model - values are either 0 or 1. I can't help thinking that's there must be a much nicer way to do it. Any suggestions? centre = numpy.array(scipy.ndimage.measurements.center_of_mass(self.bits)) vectors = [] for x in xrange(R): for y in xrange(R): for z in xrange(R): if self.bits[x,y,z]: vectors.append([x,y,z]) vectors = numpy.array(vectors) distances = numpy.sqrt(numpy.sum((vectors-centre) ** 2.0, axis=1)) av_dist = numpy.average(distances)