I am trying to convert two different Tensors to numpy arrays, same way to construct the array, but one display as a Numpy array, and the other one displays a kind of odd format with the word tensor follow by the value in parenthesis, “Tensor(value)”.

-----------------------------CODE--------------------------------

prob, index = output.topk(5)

index_top5 = np.array([index[0][0], index[0][1],index[0][2], index[0][3],index[0][4]])

prob_top5 = np.array([prob[0][0], prob[0][1],prob[0][2], prob[0][3],prob[0][4]])

-----------------------------Results--------------------------------

<class ‘torch.Tensor’>

tensor([[0.996515, 0.003395, 0.000041, 0.000018, 0.000013]])

<class ‘torch.Tensor’>

tensor([[ 94, 55, 77, 1, 83]])

<class ‘numpy.ndarray’>

[94 55 77 1 83]

<class ‘numpy.ndarray’>

[tensor(0.996515) tensor(1.00000e-03 *

3.394803)

tensor(1.00000e-05 *

4.111325)

tensor(1.00000e-05 *

1.837573)

tensor(1.00000e-05 *

1.340192)]