nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/dataset/DataSet.java
public static DataSet merge(List<DataSet> data) {
        if (data.isEmpty())
            throw new IllegalArgumentException("Unable to merge empty dataset");

        int nonEmpty = 0;
        boolean anyFeaturesPreset = false;
        boolean anyLabelsPreset = false;
        boolean first = true;
        for(DataSet ds : data){
            if(ds.isEmpty()){
                continue;
            }
            nonEmpty++;

            if(anyFeaturesPreset && ds.getFeatures() == null || (!first && !anyFeaturesPreset && ds.getFeatures() != null)){
                throw new IllegalStateException("Cannot merge features: encountered null features in one or more DataSets");
            }
            if(anyLabelsPreset && ds.getLabels() == null || (!first && !anyLabelsPreset && ds.getLabels() != null)){
                throw new IllegalStateException("Cannot merge labels: enountered null labels in one or more DataSets");
            }

            anyFeaturesPreset |= ds.getFeatures() != null;
            anyLabelsPreset |= ds.getLabels() != null;
            first = false;
        }

        INDArray[] featuresToMerge = new INDArray[nonEmpty];
        INDArray[] labelsToMerge = new INDArray[nonEmpty];
        INDArray[] featuresMasksToMerge = null;
        INDArray[] labelsMasksToMerge = null;
        int count = 0;
        for (DataSet ds : data) {
            if(ds.isEmpty())
                continue;
            featuresToMerge[count] = ds.getFeatureMatrix();
            labelsToMerge[count] = ds.getLabels();

            if (ds.getFeaturesMaskArray() != null) {
                if (featuresMasksToMerge == null) {
                    featuresMasksToMerge = new INDArray[data.size()];
                }
                featuresMasksToMerge[count] = ds.getFeaturesMaskArray();
            }
            if (ds.getLabelsMaskArray() != null) {
                if (labelsMasksToMerge == null) {
                    labelsMasksToMerge = new INDArray[data.size()];
                }
                labelsMasksToMerge[count] = ds.getLabelsMaskArray();
            }

            count++;
        }

        INDArray featuresOut;
        INDArray labelsOut;
        INDArray featuresMaskOut;
        INDArray labelsMaskOut;

        Pair<INDArray, INDArray> fp = DataSetUtil.mergeFeatures(featuresToMerge, featuresMasksToMerge);
        featuresOut = fp.getFirst();
        featuresMaskOut = fp.getSecond();

        Pair<INDArray, INDArray> lp = DataSetUtil.mergeLabels(labelsToMerge, labelsMasksToMerge);
        labelsOut = lp.getFirst();
        labelsMaskOut = lp.getSecond();

        DataSet dataset = new DataSet(featuresOut, labelsOut, featuresMaskOut, labelsMaskOut);

        List<Serializable> meta = null;
        for (DataSet ds : data) {
            if (ds.getExampleMetaData() == null || ds.getExampleMetaData().size() != ds.numExamples()) {
                meta = null;
                break;
            }
            if (meta == null)
                meta = new ArrayList<>();
            meta.addAll(ds.getExampleMetaData());
        }
        if (meta != null) {
            dataset.setExampleMetaData(meta);
        }

        return dataset;
    }
public static DataSet merge(List<DataSet> data) {
        if (data.isEmpty())
            throw new IllegalArgumentException("Unable to merge empty dataset");

        int nonEmpty = 0;
        boolean anyFeaturesPreset = false;
        boolean anyLabelsPreset = false;
        boolean first = true;
        for(DataSet ds : data){
            if(ds.isEmpty()){
                continue;
            }
            nonEmpty++;

            if(anyFeaturesPreset && ds.getFeatures() == null || (!first && !anyFeaturesPreset && ds.getFeatures() != null)){
                throw new IllegalStateException("Cannot merge features: encountered null features in one or more DataSets");
            }
            if(anyLabelsPreset && ds.getLabels() == null || (!first && !anyLabelsPreset && ds.getLabels() != null)){
                throw new IllegalStateException("Cannot merge labels: enountered null labels in one or more DataSets");
            }

            anyFeaturesPreset |= ds.getFeatures() != null;
            anyLabelsPreset |= ds.getLabels() != null;
            first = false;
        }

        INDArray[] featuresToMerge = new INDArray[nonEmpty];
        INDArray[] labelsToMerge = new INDArray[nonEmpty];
        INDArray[] featuresMasksToMerge = null;
        INDArray[] labelsMasksToMerge = null;
        int count = 0;
        for (DataSet ds : data) {
            if(ds.isEmpty())
                continue;
            featuresToMerge[count] = ds.getFeatureMatrix();
            labelsToMerge[count] = ds.getLabels();

            if (ds.getFeaturesMaskArray() != null) {
                if (featuresMasksToMerge == null) {
                    featuresMasksToMerge = new INDArray[data.size()];
                }
                featuresMasksToMerge[count] = ds.getFeaturesMaskArray();
            }
            if (ds.getLabelsMaskArray() != null) {
                if (labelsMasksToMerge == null) {
                    labelsMasksToMerge = new INDArray[data.size()];
                }
                labelsMasksToMerge[count] = ds.getLabelsMaskArray();
            }

            count++;
        }

        INDArray featuresOut;
        INDArray labelsOut;
        INDArray featuresMaskOut;
        INDArray labelsMaskOut;

        Pair<INDArray, INDArray> fp = DataSetUtil.mergeFeatures(featuresToMerge, featuresMasksToMerge);
        featuresOut = fp.getFirst();
        featuresMaskOut = fp.getSecond();

        Pair<INDArray, INDArray> lp = DataSetUtil.mergeLabels(labelsToMerge, labelsMasksToMerge);
        labelsOut = lp.getFirst();
        labelsMaskOut = lp.getSecond();

        DataSet dataset = new DataSet(featuresOut, labelsOut, featuresMaskOut, labelsMaskOut);

        List<Serializable> meta = null;
        for (DataSet ds : data) {
            if (ds.getExampleMetaData() == null || ds.getExampleMetaData().size() != ds.numExamples()) {
                meta = null;
                break;
            }
            if (meta == null)
                meta = new ArrayList<>();
            meta.addAll(ds.getExampleMetaData());
        }
        if (meta != null) {
            dataset.setExampleMetaData(meta);
        }

        return dataset;
    }
public static DataSet merge ( List < DataSet > data ) { if ( data . isEmpty ( ) ) throw new IllegalArgumentException ( "Unable to merge empty dataset" ) ; int nonEmpty = 0 ; boolean anyFeaturesPreset = false ; boolean anyLabelsPreset = false ; boolean first = true ; for ( DataSet ds : data ) { if ( ds . isEmpty ( ) ) { continue ; } nonEmpty ++ ; if ( anyFeaturesPreset && ds . getFeatures ( ) == null || ( ! first && ! anyFeaturesPreset && ds . getFeatures ( ) != null ) ) { throw new IllegalStateException ( "Cannot merge features: encountered null features in one or more DataSets" ) ; } if ( anyLabelsPreset && ds . getLabels ( ) == null || ( ! first && ! anyLabelsPreset && ds . getLabels ( ) != null ) ) { throw new IllegalStateException ( "Cannot merge labels: enountered null labels in one or more DataSets" ) ; } anyFeaturesPreset |= ds . getFeatures ( ) != null ; anyLabelsPreset |= ds . getLabels ( ) != null ; first = false ; } INDArray [ ] featuresToMerge = new INDArray [ nonEmpty ] ; INDArray [ ] labelsToMerge = new INDArray [ nonEmpty ] ; INDArray [ ] featuresMasksToMerge = null ; INDArray [ ] labelsMasksToMerge = null ; int count = 0 ; for ( DataSet ds : data ) { if ( ds . isEmpty ( ) ) continue ; featuresToMerge [ count ] = ds . getFeatureMatrix ( ) ; labelsToMerge [ count ] = ds . getLabels ( ) ; if ( ds . getFeaturesMaskArray ( ) != null ) { if ( featuresMasksToMerge == null ) { featuresMasksToMerge = new INDArray [ data . size ( ) ] ; } featuresMasksToMerge [ count ] = ds . getFeaturesMaskArray ( ) ; } if ( ds . getLabelsMaskArray ( ) != null ) { if ( labelsMasksToMerge == null ) { labelsMasksToMerge = new INDArray [ data . size ( ) ] ; } labelsMasksToMerge [ count ] = ds . getLabelsMaskArray ( ) ; } count ++ ; } INDArray featuresOut ; INDArray labelsOut ; INDArray featuresMaskOut ; INDArray labelsMaskOut ; Pair < INDArray , INDArray > fp = DataSetUtil . mergeFeatures ( featuresToMerge , featuresMasksToMerge ) ; featuresOut = fp . getFirst ( ) ; featuresMaskOut = fp . getSecond ( ) ; Pair < INDArray , INDArray > lp = DataSetUtil . mergeLabels ( labelsToMerge , labelsMasksToMerge ) ; labelsOut = lp . getFirst ( ) ; labelsMaskOut = lp . getSecond ( ) ; DataSet dataset = new DataSet ( featuresOut , labelsOut , featuresMaskOut , labelsMaskOut ) ; List < Serializable > meta = null ; for ( DataSet ds : data ) { if ( ds . getExampleMetaData ( ) == null || ds . getExampleMetaData ( ) . size ( ) != ds . numExamples ( ) ) { meta = null ; break ; } if ( meta == null ) meta = new ArrayList <> ( ) ; meta . addAll ( ds . getExampleMetaData ( ) ) ; } if ( meta != null ) { dataset . setExampleMetaData ( meta ) ; } return dataset ; }
Merge the list of datasets in to one list.
All the rows are merged in to one dataset

@param data the data to merge
@return a single dataset
Merge the list of datasets in to one list . All the rows are merged in to one dataset