def train(self, x, d, epochs=10, shuffle=False):
        N = len(x)
        if not len(d) == N:
            raise ValueError('The length of vector d and matrix x must agree.')  
        if not len(x[0]) == self.n_input:
            raise ValueError('The number of network inputs is not correct.')
        if self.outputs == 1:
            if not len(d.shape) == 1:
                raise ValueError('For one output MLP the d must have one dimension')
        else:
            if not d.shape[1] == self.outputs:
                raise ValueError('The number of outputs must agree with number of columns in d')
        try:    
            x = np.array(x)
            d = np.array(d)
        except:
            raise ValueError('Impossible to convert x or d to a numpy array')
        if self.outputs == 1:
            e = np.zeros(epochs*N)
        else:
            e = np.zeros((epochs*N, self.outputs))
        MSE = np.zeros(epochs)
        if shuffle:
            randomize = np.arange(len(x))
            np.random.shuffle(randomize)
            x = x[randomize]
            d = d[randomize]
        for epoch in range(epochs):
            for k in range(N):
                self.predict(x[k])
                e[(epoch*N)+k] = self.update(d[k])
            MSE[epoch] = np.sum(e[epoch*N:(epoch+1)*N-1]**2) / N
        return e, MSE