Export torch.tensor to csv

Hello everyone.
Very simple and straightforward question.

I have a model that at the end of every training epoch generates a torch.tensor of dim[6].

I want to append it to a .csv file (at the end of each epoch) in order to the plot how the tensor evolves in time during training.

Is there a simple way to do that? Didn’t find anything online so far.

Thanks in advance. Best, kim

I guess you could just use Numpy for that

import numpy as np        

your_file = open('filename', 'ab')
for epoch in range(num_epochs):
    # ...

Can you elaborate (‘filename’, ‘ab’). What is ab?

ab opens a file for appending in binary format. You can find the different modes here.