Home > front end >  AttributeError: 'list' object has no attribute 'numpy'
AttributeError: 'list' object has no attribute 'numpy'

Time:12-22

I was trying to convert a list to array with this code:

[t.numpy() for t in super_final_predictions]

But, An Unexpected error occurs

AttributeError: 'list' object has no attribute 'numpy'

If anyone could help me it would be greatful.

CodePudding user response:

If you are just trying to convert the list t to an array, you can just say t_array = np.array(t)

CodePudding user response:

try this way to convert list to numpy array l = [1,2,3,4,5] arr = numpy.array(l)

CodePudding user response:

To convert lists to Numpy arrays, you should be using the following syntax

[numpy.array(t) for t in super_final_predictions]

Please note that this answer that I'm giving assumes that super_final_predictions contains multiple lists and the output you want is a list of numpy arrays.

If you want to convert the entire super_final_predictions list to a n-dimensional numpy array, you should be using

numpy.array(super_final_predictions)

Also, specify the datatypes while creating the array as it may be important for your use case. For instance :

numpy.array(super_final_predictions , dtype = np.uint8)

CodePudding user response:

Try:

[np.array(t) for t in super_final_predictions]

Or just simply:

np.array(super_final_predictions)

The second code would convert the whole nested list to an array, which should be what you want.

  • Related