TypeError: Data type not understood, numpy.zeros
Solution 1
You need to pass in a tuple. Try np.zeros((count, count))
.
Further documentation on this method available here: https://docs.scipy.org/doc/numpy/reference/generated/numpy.zeros.html
Solution 2
Use a sequence of ints:
newRatios = np.zeros((count,count))
Shape parameter of zeros
accepts int or sequence of ints. Refer docs.
Related videos on Youtube
Fletchy
Updated on June 04, 2022Comments
-
Fletchy almost 2 years
I am getting an error while running my code. The error I receive is:
Traceback (most recent call last): File "/Users/penguin/PycharmProjects/Greatness/venv/Recipes.py", line 153, in <module> newRatios = np.zeros(count,count) TypeError: data type not understood Process finished with exit code 1
My code is:
count1 = 0 count2 = 0 newRatios = np.zeros(count,count) print(newRatios) for ep in XDF['EmailPrefix']: for ep2 in XDF['EmailPrefix']: if count1 != count2: newRatios[count1,count2] = fuzz.token_sort_ratio(ep,ep2) else: newRatios[count1,count2] = None count2 += 1 count1 += 1 if(count1 == 2500): print('Halfway') print(newRatios)
The variable count represents a integer value of about 5000. I apologize I can only give code snippets instead of the entire file, but I am not allowed to disclose the full file.
Not really sure why I'm getting this error, I have tried a few different methods of setting up numpy zeros array and setting up a 2D matrix. Please note that I import numpy as np so thats why its called np. I am using python3, if you have any other suggestions for setting up a 2D array and accessing it better than I am here that would be appreciated as well.