3

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.

Fletchy
  • 311
  • 1
  • 4
  • 18

3 Answers3

8

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

Benjamin Engwall
  • 294
  • 1
  • 11
1

Use a sequence of ints:

newRatios = np.zeros((count,count))

Shape parameter of zeros accepts int or sequence of ints. Refer docs.

Austin
  • 25,759
  • 4
  • 25
  • 48
0

np.zeros accepts an iterable as the shape argument. You need to pass your arguments as np.zeros((count,count)). Notice the extra parenthesis. What you're currently doing is passing in count as the shape and then passing in count again as a datatype. It doesn't recognize the datatype that count represents, hence the error.

enumaris
  • 1,868
  • 1
  • 16
  • 34