2014-11-12 11 views
6

Sto cercando di ottenere il file di output esteso arrf da un array multidimensionale in Java. E ho importato la libreria di weka, tuttavia ho ricevuto un errore; The type FastVector<E> is deprecated.Il tipo FastVector <E> è obsoleto

Cosa posso utilizzare invece di FastVector e come posso riscrivere il codice riportato di seguito?

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(); 

risposta

13

Ora Weka utilizza più ArrayList tipizzati. È possibile utilizzare ArrayList<Attribute> per questo:

ArrayList<Attribute> atts = new ArrayList<Attribute>(); 
    for (int att = 0; att < numAtts; att++) { 
     atts.add(new Attribute("Attribute" + att, att)); 
    } 
+2

Sì, vedo che, ma come posso usare ArrayList nel codice di cui sopra? – EngineerEngin

+0

Ho modificato la mia risposta con uno snippet di codice. Dovrebbe essere semplice come cambiare il tipo di variabile atts. – Chris

+0

Grazie, funziona. L'errore di FastVector è andato. – EngineerEngin