I am attempting a bit of knn classification. when i try to normalize the data in an array i keep getting the above error.
norm_val = 100.00
for i in range(0, len(ListData)):
ListData[i][0] = int(ListData[i][0]/max_val)
I'm getting the error on the last line which says, 'int' object is not subscriptable.
Thanks
ListData
appears to be a list of integers (or at least a list that also contains integers).
Therefore, ListData[i]
returns the i
th integer of the list. And since there is no such thing as "the first element of an integer", so you get this error when trying to access ListData[i][0]
.
Aside from that, if you're aiming to divide all items of a list by max_val
, you can simply use a list comprehension:
ListData = [int(item/max_val) for item in ListData]