1

I want interate a DataSetIterator and add it into a DataSet. Iterate is easy:

while (iterator.hasNext()) {
    DataSet next = iterator.next();
    dataSet.addRow(next, dataSet.numExamples()); // isn't work
}

if the DataSetIterator batch size is 1, when I do dataSet.addRow(next, 1); this just replace this first element with the next one. If batch size is 2, then raise the exception: Exception in thread "main" java.lang.IllegalArgumentException: NDArrayIndex is out of range. Beginning index: 2 must be less than its size: 2

I also want know how add a DataSet into another DataSet.

Reinier Hernández
  • 428
  • 1
  • 6
  • 22

2 Answers2

1

DataSet class has the static merge() method. On this method, you pass a List<DataSet> and returns all DataSet contains into List like one only DataSet.

ArrayList<DataSet> data_list = new ArrayList<DataSet>();
// add some data into data_list
DataSet allData = DataSet.merge(data_list); // all DataSet into data_list are merged into allData
Reinier Hernández
  • 428
  • 1
  • 6
  • 22
0

The exception thrown by the statement:

dataSet.addRow(next, dataSet.numExamples()); // isn't work

should give you a clue of why it is not working.

The likely reason the above is raising an exception is because the row index specified by the second parameter of addRow() is 0 based, so valid values range from 0 to numExamples() -1.

Regarding adding rows to a DataSet, check if there is an append() method in the DataSet or an addRow() method that does not require the caller to specify the row index. To merge one DataSet instance with another, check if there is a merge() method available.

Hope this helps!