So I have been writing a code to standardize the elements of a matrix and the function I used is as follows:
def preprocess(Data):
if stdn ==True:
st=np.empty((Data.shape[0],Data.shape[1]))
for i in xrange(0,Data.shape[0]):
st[i,0]=Data[i,0]
for i in xrange(1,Data.shape[1]):
st[:,i]=((Data[:,i]-np.min(Data[:,i]))/(np.ptp(Data[:,i])))
np.random.shuffle(st)
return st
else:
return Data
It works very well outside the class but when used inside of it it gives me this error:
AttributeError: 'tuple' object has no attribute 'shape'
Any idea on how I can fix it?? P.S. This is a KNN classification code
The Python "AttributeError: 'list' object has no attribute" occurs when we access an attribute that doesn't exist on a list. To solve the error, access the list element at a specific index or correct the assignment.
The shape of a simple Python tuple or list can be obtained with the built-in len() function. len() will return an integer that describes the number of objects in the tuple or list.
The Python "TypeError: 'tuple' object is not callable" occurs when we try to call a tuple as if it were a function. To solve the error, make sure to use square brackets when accessing a tuple at a specific index, e.g. my_tuple[0] .
AttributeError can be defined as an error that is raised when an attribute reference or assignment fails. For example, if we take a variable x we are assigned a value of 10. In this process suppose we want to append another value to that variable. It's not possible.
According to the error you posted, Data
is of type tuple and there is no attribute shape
defined for data. You could try casting Data
when you call your preprocess
function, e.g.:
preprocess(numpy.array(Data))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With