def neurite_centre_of_mass(neurite):
    '''Calculate and return centre of mass of a neurite.'''
    centre_of_mass = np.zeros(3)
    total_volume = 0

    seg_vol = np.array(map(mm.segment_volume, nm.iter_segments(neurite)))
    seg_centre_of_mass = np.array(map(segment_centre_of_mass, nm.iter_segments(neurite)))

    # multiply array of scalars with array of arrays
    # http://stackoverflow.com/questions/5795700/multiply-numpy-array-of-scalars-by-array-of-vectors
    seg_centre_of_mass = seg_centre_of_mass * seg_vol[:, np.newaxis]
    centre_of_mass = np.sum(seg_centre_of_mass, axis=0)
    total_volume = np.sum(seg_vol)
    return centre_of_mass / total_volume
Calculate and return centre of mass of a neurite.