Java – fastvector type is not recommended
•
Java
I tried to get an arrf extension output file from a multidimensional array in Java I imported the Weka library, but I received an error; Type fastvector < E > deprecated
What can I use instead of fastvector and how can I rewrite the following code?
import weka.core.FastVector; //Error: The type FastVector<E> is deprecated.
int [][] myArray = new int[45194][12541];
for (int i = 0; i < myArray.length; i++) {
for (int j = 0; j < myArray[0].length; j++) {
System.out.print(myArray[i][j]+" ");
}
System.out.println("");
}
int numAtts = myArray[0].length;
FastVector atts = new FastVector(numAtts);
for (int att = 0; att < numAtts; att++) {
atts.addElement(new Attribute("Attribute" + att,att));
}
int numInstances = myArray.length;
Instances dataset = new Instances("Dataset",atts,numInstances);
for (int inst = 0; inst < numInstances; inst++) {
dataset.add(new Instance(1.0,myArray[inst])); //Error: Cannot instantiate the type Instance
}
BufferedWriter writer = new BufferedWriter(new FileWriter("test.arff"));
writer.write(dataset.toString());
writer.flush();
writer.close();
Solution
Weka now uses typed ArrayLists in most places You can use ArrayList < attribute > to this:
ArrayList<Attribute> atts = new ArrayList<Attribute>();
for (int att = 0; att < numAtts; att++) {
atts.add(new Attribute("Attribute" + att,att));
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
