def __tomo_linear_inv(freqs, ops, weights=None, trace=None):
    '\n    Reconstruct a matrix through linear inversion.\n\n    Args:\n        freqs (list[float]): list of observed frequences.\n        ops (list[np.array]): list of corresponding projectors.\n        weights (list[float] or array_like):\n            weights to be used for weighted fitting.\n        trace (float or None): trace of returned operator.\n\n    Returns:\n        numpy.array: A numpy array of the reconstructed operator.\n    '
    if (weights is not None):
        W = np.array(weights)
        if (W.ndim == 1):
            W = np.diag(W)
    S = np.array([vectorize(m).conj() for m in ops]).reshape(len(ops), ops[0].size)
    if (weights is not None):
        S = np.dot(W, S)
    v = np.array(freqs)
    if (weights is not None):
        v = np.dot(W, freqs)
    Sdg = S.T.conj()
    inv = np.linalg.pinv(np.dot(Sdg, S))
    ret = devectorize(np.dot(inv, np.dot(Sdg, v)))
    if (trace is not None):
        ret = ((trace * ret) / np.trace(ret))
    return ret
Reconstruct a matrix through linear inversion.

Args:
    freqs (list[float]): list of observed frequences.
    ops (list[np.array]): list of corresponding projectors.
    weights (list[float] or array_like):
        weights to be used for weighted fitting.
    trace (float or None): trace of returned operator.

Returns:
    numpy.array: A numpy array of the reconstructed operator.
def __tomo_linear_inv(freqs, ops, weights=None, trace=None):
    '\n    Reconstruct a matrix through linear inversion.\n\n    Args:\n        freqs (list[float]): list of observed frequences.\n        ops (list[np.array]): list of corresponding projectors.\n        weights (list[float] or array_like):\n            weights to be used for weighted fitting.\n        trace (float or None): trace of returned operator.\n\n    Returns:\n        numpy.array: A numpy array of the reconstructed operator.\n    '
    if (weights is not None):
        W = np.array(weights)
        if (W.ndim == 1):
            W = np.diag(W)
    S = np.array([vectorize(m).conj() for m in ops]).reshape(len(ops), ops[0].size)
    if (weights is not None):
        S = np.dot(W, S)
    v = np.array(freqs)
    if (weights is not None):
        v = np.dot(W, freqs)
    Sdg = S.T.conj()
    inv = np.linalg.pinv(np.dot(Sdg, S))
    ret = devectorize(np.dot(inv, np.dot(Sdg, v)))
    if (trace is not None):
        ret = ((trace * ret) / np.trace(ret))
    return ret