<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample_mgrid(self, mgrid: np.array) -> np.array: """Sample a mesh-grid array and return the result. The :any:`sample_ogrid` method performs better as there is a lot of overhead when working with large mesh-grids. Args: mgrid (numpy.ndarray):
 A mesh-grid array of points to sample. A contiguous array of type `numpy.float32` is preferred. Returns: numpy.ndarray: An array of sampled points. This array has the shape: ``mgrid.shape[:-1]``. The ``dtype`` is `numpy.float32`. """

        mgrid = np.ascontiguousarray(mgrid, np.float32)
        if mgrid.shape[0] != self.dimensions:
            raise ValueError(
                "mgrid.shape[0] must equal self.dimensions, "
                "%r[0] != %r" % (mgrid.shape, self.dimensions)
            )
        out = np.ndarray(mgrid.shape[1:], np.float32)
        if mgrid.shape[1:] != out.shape:
            raise ValueError(
                "mgrid.shape[1:] must equal out.shape, "
                "%r[1:] != %r" % (mgrid.shape, out.shape)
            )
        lib.NoiseSampleMeshGrid(
            self._tdl_noise_c,
            out.size,
            ffi.cast("float*", mgrid.ctypes.data),
            ffi.cast("float*", out.ctypes.data),
        )
        return out