Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'list' object has no attribute 'reshape'

Tags:

python

numpy

I've been following a video tutorial on python, and I received an attribute error regardless typing the exact same code as the video.

import numpy as np

A = np.array([[56.0, 0.0, 4,4, 68.0],
             [1.2, 104.0, 52.0, 8.0],
             [1.8, 135.0, 99.0, 0.9]])

cal = A.sum(axis=0)
percentage = 100*A/cal.reshape(1,4)
print(percentage)

The attribute error points to the percentage variable, stating that the list has no attribute 'reshape'. I searched for solutions and saw on the documentation that it has been "Deprecated since version 0.19.0. Calling this method will raise an error. Please call .values.reshape(...) instead.", and I tried the updated one according to what the documentation had provided.

percentage = 100*A/cal.values.reshape(1,4)

After this attempt, it still led to an attribute error. I don't know if I did it wrong because I'm completely new to python.

like image 355
Mizile Avatar asked Nov 29 '25 18:11

Mizile


1 Answers

I got this warning:

VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. A = np.array([[56.0, 0.0, 4,4, 68.0],

And according to this question: numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences

This has to do with the creation of arrays from lists of unequal length. So I presume that in this line:

[56.0, 0.0, 4,4, 68.0]

The 4,4 should have been a 4.4, right?

like image 77
haxor789 Avatar answered Dec 01 '25 06:12

haxor789



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!