The most direct approach is to create an array of bounding boxes, keeping at each point the distance to the center of the sphere:
>>> radius = 3 >>> r2 = np.arange(-radius, radius+1)**2 >>> dist2 = r2[:, None, None] + r2[:, None] + r2 >>> volume = np.sum(dist2 <= radius**2) >>> volume 123
A 2D document is easier to visualize:
>>> dist2 = r2[:, None] + r2 >>> (dist2 <= radius**2).astype(np.int) array([[0, 0, 0, 1, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 1, 0, 0, 0]]) >>> np.sum(dist2 <= radius**2) 29