<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mean_and_cov(samples, weights):
 """ Compute the weighted mean and covariance of the samples. Parameters samples : `~numpy.ndarray` with shape (nsamples, ndim) 2-D array containing data samples. This ordering is equivalent to using `rowvar=False` in `~numpy.cov`. weights : `~numpy.ndarray` with shape (nsamples,) 1-D array of sample weights. Returns ------- mean : `~numpy.ndarray` with shape (ndim,) Weighted sample mean vector. cov : `~numpy.ndarray` with shape (ndim, ndim) Weighted sample covariance matrix. Notes ----- Implements the formulae found `here <https://goo.gl/emWFLR>`_. """


    # Compute the weighted mean.
    mean = np.average(samples, weights=weights, axis=0)

    # Compute the weighted covariance.
    dx = samples - mean
    wsum = np.sum(weights)
    w2sum = np.sum(weights**2)
    cov = wsum / (wsum**2 - w2sum) * np.einsum('i,ij,ik', weights, dx, dx)

    return mean, cov