<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def Sens_m2_sample(poly, dist, samples, rule="R"):
 """ Second order sensitivity indices estimated using Saltelli's method. Args: poly (chaospy.Poly):
 If provided, evaluated samples through polynomials before returned. dist (chaopy.Dist):
 distribution to sample from. samples (int):
 The number of samples to draw for each matrix. rule (str):
 Scheme for generating random samples. Return: (numpy.ndarray):
 array with `shape == (len(dist), len(dist), len(poly))` where `sens[dim1][dim2][pol]` is the correlating sensitivity between dimension `dim1` and `dim2` and polynomial index `pol`. Examples: [q0^2, q0q1, q1^2] [[[ 0.008 0.0026 0. ] [-0.0871 1.1516 1.2851]] <BLANKLINE> [[-0.0871 1.1516 1.2851] [ 0. 0.7981 1.38 ]]] """

    dim = len(dist)

    generator = Saltelli(dist, samples, poly, rule=rule)

    zeros = [0]*dim
    ones = [1]*dim
    index = [0]*dim

    variance = numpy.var(generator[zeros], -1)

    matrix_0 = generator[zeros]
    matrix_1 = generator[ones]
    mean = .5*(numpy.mean(matrix_1) + numpy.mean(matrix_0))

    matrix_0 -= mean
    matrix_1 -= mean

    out = numpy.empty((dim, dim)+poly.shape)
    for dim1 in range(dim):

        index[dim1] = 1
        matrix = generator[index]-mean
        out[dim1, dim1] = numpy.mean(
            matrix_1*(matrix-matrix_0),
            -1,
        ) / numpy.where(variance, variance, 1)

        for dim2 in range(dim1+1, dim):

            index[dim2] = 1

            matrix = generator[index]-mean

            out[dim1, dim2] = out[dim2, dim1] = numpy.mean(
                matrix_1*(matrix-matrix_0),
                -1,
            ) / numpy.where(variance, variance, 1)

            index[dim2] = 0

        index[dim1] = 0

    return out