Reputation: 123
I have a script for doing some math computations, where I am using dictionaries to represent polynomials. Originally my code started off as this:
p = {}
p[(0,0,0)] = 1
Then, to generalize, I replaced the second command by this:
p[tuple(numpy.zeros((3,),dtype=int))] = 1
What I do not understand is why this single change affects the outcome of the program. How are these different?
Upvotes: 0
Views: 79
Reputation: 41168
As I said in my comment, the difference is the numpy
version creates a tuple
of numpy.int64
s instead of regular Python int
s:
>>> import numpy
>>> t1 = (0,0,0)
>>> type(t1[0])
<class 'int'>
>>> t2 = tuple(numpy.zeros((3,),dtype=int))
>>> type(t2[0])
<class 'numpy.int64'>
This is unlikely to make a difference but can in a few cases, for example with some itertools
arguments. There is a related bug issue on this too, so watch this space.
Upvotes: 1