Convert tensor to ndarray to add to each row in a dataframe

I have a dataframe in the form where rows indicate ids and columns indicate the no of classes.
Say I have 10 classes then column names would be ‘class1’, ‘class2’, . . ., ‘class10’.
For each row I am predicting the probabilities of belonging to the various classes.
Say for 9 classes these are the calculated probabilities stored in a tensor.
tensor([1.3953e-05, 3.3629e-01, 2.9408e-01, 3.5847e-01, 1.8039e-05, 9.7759e-06,
1.1096e-02, 7.1202e-06, 1.9519e-05])

What would be the best way to add this tensor to the particular row for which I am calculating these probabilities. Given I want to add it to a dataframe.
Also, how can I limit the trailing no of digits after the decimal in the tensor?

1 Like

It seems more like a Pandas related question, so probably StackOverflow would be a better place to ask, as there are probably more Pandas users.
However, as far as I understood the question, this should work:

num_samples = 10
num_classes = 9
df = pd.DataFrame(index=range(num_samples), columns=[str(x) for x in range(num_classes)])
for i in range(num_samples):
    df.iloc[i] = torch.randn(1, num_classes).numpy().round(2)