code: def wmean_and_var(W, x):
      
      m = np.average(x, weights=W, axis=0)
      m2 = np.average(x**2, weights=W, axis=0)
      v = m2 - m**2
      return {'mean': m, 'var': v}
docs: Component-wise weighted mean and variance.
  
      Parameters
      ----------
      W: (N,) ndarray
          normalised weights (must be >=0 and sum to one). 
      x: ndarray (such that shape[0]==N)
          data 
  
      Returns
      -------
      dictionary 
          {'mean':weighted_means, 'var':weighted_variances}