save to csv - numpy.ndarray' object has no attribute 'append'
I'm trying to append the filenames of the images during training into a csv file, but getting an error. I can print the values okay but cannot append to csv file for some reason. Here is the full code:
  File &quot;train_filename.py&quot;, line 140, in &lt;module&gt;
    names_preds.append() + '\n'
AttributeError: 'numpy.ndarray' object has no attribute 'append'

        with open('preds_base_model_teste1016.csv','a') as fd:
            #dict_writer = csv.writer(fd)
            #dict_writer.writerow('Target' + '\n')
            #dict_writer.writerow( ','.join(map(str, preds.detach().tolist())) + '\n')
            #dict_writer.writerow('Prediction' + '\n')
            #dict_writer.writerow( ','.join(map(str, targets.detach().tolist())) + '\n')
            #fd.write('Target' + '\n')
            fd.write(','.join(map(str, preds.detach().tolist())) + '\n')
            #fd.write('Prediction' + '\n')
            fd.write( ','.join(map(str, targets.detach().tolist())) + '\n')
            #fd.write('Image_Name' + '\n')
            np.append(paths)
            #fd.write([filename])



Use concatenate instead of append as described in the docs.
It does look like you are trying to add nothing to the array, however.
You should use it like this:
names_preds.concatenate(some_value) where the value inside concatenate is what you want to add to the array.
To save a numpy array to a csv file, there is an easier way:
numpy.savetxt(&quot;foo.csv&quot;, names_preds, delimiter=&quot;,&quot;)

See details in this answer.
Replace your line:
np.append(paths)

with
with open('preds_base_model_teste1016.csv','a') as fd:
    np.savetxt(fd, names_preds, delimiter=&quot;,&quot;)

That will append all of the paths to the file you already specified.
Update:
Per your question in the comment, to put multiple arrays together so you end up with columns, you could try:
with open('preds_base_model_teste1016.csv','a') as fd:
    np.savetxt(fd, list(zip(a,b,c)), delimiter=&quot;,&quot;)

where a, b, and c are the arrays you want as columns.
