'Fit the transformer on dense data.'

def _dense_fit(self, X, strategy, missing_values, axis):

    X = check_array(X, force_all_finite=False)
    mask = _get_mask(X, missing_values)
    masked_X = ma.masked_array(X, mask=mask)
    if (strategy == 'mean'):
        mean_masked = np.ma.mean(masked_X, axis=axis)
        mean = np.ma.getdata(mean_masked)
        mean[np.ma.getmask(mean_masked)] = np.nan
        return mean
    elif (strategy == 'median'):
        if (tuple((int(v) for v in np.__version__.split('.')[:2])) < (1, 5)):
            masked_X.mask = np.logical_or(masked_X.mask, np.isnan(X))
        median_masked = np.ma.median(masked_X, axis=axis)
        median = np.ma.getdata(median_masked)
        median[np.ma.getmaskarray(median_masked)] = np.nan
        return median
    elif (strategy == 'most_frequent'):
        if (axis == 0):
            X = X.transpose()
            mask = mask.transpose()
        most_frequent = np.empty(X.shape[0])
        for (i, (row, row_mask)) in enumerate(zip(X[:], mask[:])):
            row_mask = np.logical_not(row_mask).astype(np.bool)
            row = row[row_mask]
            most_frequent[i] = _most_frequent(row, np.nan, 0)
        return most_frequent
