We have developed a novel approach to compute, in an efficient and versatile way, the gravity anomaly produced by an arbitrary, discrete 3D distribution of density contrast. The method allows adjustable precision and is particularly suited for the interpretation of sedimentary basins. Because the gravity field decays with the square of the distance, we use a discrete Green’s operator that may be made much smaller than the whole study area. For irregularly positioned observations, this discrete Green’s operator must be computed just at the first iteration, and because each of its horizontal layers presents a center of symmetry, only one-eighth of its total elements need to be calculated. Furthermore, for gridded data on a plane, this operator develops translation symmetry for the whole region of interest and has to be computed just once for a single arbitrary observation position. The gravity anomaly is obtained as the product of this small operator by any arbitrary density contrast distribution in a convolution-like operation. We use the proposed modeling to estimate the basement relief of a basin with density contrast varying along only using a smaller Green’s operator at all iterations. The median of the absolute differences between relief estimates, using the small and a large operator (the latter covering the whole basin) has been approximately 9 m for a 3.6 km deep basin. We also successfully inverted the anomaly of a simulated basin with density contrast varying laterally and vertically, and a real anomaly produced by a steeply dipping basement. The proposed modeling is very fast. For 10,000 observations gridded on a plane, the inversion using the proposed approach for irregularly spaced data is two orders of magnitude faster than using an analytically derived fitting, and this ratio increases enormously with the number of observations.