<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def samples_from_getdist_chains(params, file_root, latex=False):
 """ Extract samples and weights from getdist chains. Parameters params: list(str) Names of parameters to be supplied to second argument of f(x|theta). file_root: str, optional Root name for getdist chains files. This variable automatically defines: - chains_file = file_root.txt - paramnames_file = file_root.paramnames but can be overidden by chains_file or paramnames_file. latex: bool, optional Also return an array of latex strings for those paramnames. Returns ------- samples: numpy.array 2D Array of samples. `shape=(len(samples), len(params))` weights: numpy.array Array of weights. `shape = (len(params),)` latex: list(str), optional list of latex strings for each parameter (if latex is provided as an argument) """


    import getdist
    samples = getdist.loadMCSamples(file_root)
    weights = samples.weights

    indices = [samples.index[p] for p in params]
    samps = samples.samples[:, indices]
    if latex:
        latex = [samples.parLabel(p) for p in params]
        return samps, weights, latex
    else:
        return samps, weights