how to append a singleton numpy array item into a list?
I am attaching the code first which will give you a better idea

`   prediction = prediction.data.max(1)[1] #gives a tensor value
    prediction = (prediction.cpu().numpy().item()) #converts that tensor into a numpy array 
    result.append(int_to_word[prediction])`


I am using pytorch for word generation. The line prediction = prediction.data.max(1)[1] gives us the class label with the maximum probability, which turns out to be a  tensor value.

prediction = (prediction.cpu().numpy().item()) this statement converts the tensor into a numpy array and the funtion item() extracts the value from the array. 

Now when I try to append this value using pattern.append(prediction)
I am getting the following error
'numpy.ndarray' object has no attribute 'append'

I am not able to understand as to why I am getting this error. I have already converted the numpy array into a scalr value, didn't I?? Still, why am I getting that error?

Can anybody please explain and provide a solution to this. I would be most grateful.

Numpy arrays are immutable with respect to their dimensions. They do not support the append operation. You'll have to declare results as a list, then append your values to your list, and then convert it to a numpy array:

result = []
...

result.append(prediction) # inside some loop

...

result = np.array(result)

