Generalized to 1D, 2D, 3D