def getDerMatrix(self,x=None,z=None,mode=None,der=None):
        self.checkInputGetDerMatrix(x,z,mode,der)
        Q = self.para[0]
        if mode == 'self_test':
            nn, D = z.shape
        else:
            nn, D = x.shape
        assert Q == old_div(len(self.hyp), (1 + 2 * D))

        w = np.exp(self.hyp[:Q])
        m = np.exp(np.reshape(self.hyp[Q:Q + Q * D], (D, Q)))
        v = np.exp(2 * np.reshape(self.hyp[Q + Q * D:], (D, Q)))

        if mode == 'self_test':               # self covariances for the test cases
            d2 = np.zeros((nn, 1, D))
        elif mode == 'train':                 # compute covariance matix for dataset x
            d2 = np.zeros((nn, nn, D))
            for j in range(D):
                xslice = np.atleast_2d(x[:, j]).T
                d2[:, :, j] = spdist.cdist(xslice, xslice, 'sqeuclidean')
        elif mode == 'cross':                 # compute covariance between data sets x and z
            d2 = np.zeros((nn, z.shape[0], D))
            for j in range(D):
                xslice = np.atleast_2d(x[:, j]).T
                zslice = np.atleast_2d(z[:, j]).T
                d2[:, :, j] = spdist.cdist(xslice, zslice, 'sqeuclidean')
        d = np.sqrt(d2)

        k = lambda d2v_dm1: np.exp(-2 * np.pi ** 2 * d2v_dm1[0]) * np.cos(2* np.pi * d2v_dm1[1])  # evaluation of the covariance
        km = lambda dm: -2 * np.pi * np.tan(2 * np.pi * dm) * dm  # remainder when differentiating w.r.t. m
        kv = lambda d2v: -d2v * (2 * np.pi) ** 2  # remainder when differentiating w.r.t. v

        A = 0.
        c = 1.
        qq = list(range(Q))
        if der < Q:                         # compute derivative matrix wrt w
            c = 1
            qq = [der]
        elif der < Q + Q * D:               # compute derivative matrix wrt sig
            p = (der - Q) % D
            q = old_div((der - Q - p), D)
            c = km(d[:, :, p] * m[p, q])
            qq = [q]
        elif der < 2 * Q * D + Q:           # compute derivative matrix wrt mu
            p = (der - (D + 1) * Q) % D
            q = old_div((der - (D + 1) * Q - p), D)
            c = kv(d2[:, :, p] * v[p, q])
            qq = [q]
        else:
            raise Exception("Wrong derivative entry in SM")

        for q in qq:
            C = w[q] * c
            for j in range(D):
                C = C * k((d2[:, :, j] * v[j, q], d[:, :, j] * m[j, q]))
                A = A + C
        return A
dataset/ETHPy150Open marionmari/pyGPs/pyGPs/Core/cov.py/SM.getDerMatrix/original