When I use the numpy functions minimum() and maximum() on boolean arrays, the type of the result prints as numpy.int32. However, a comparison with the numpy.int32 type fails (even after a cast). Is this a bug?
g = np.ones((5, 5), dtype = np.bool)
h = np.maximum(g, 4)
i = np.int32(h)
print 'type of g ', g.dtype.type # prints <type 'numpy.bool_'>
print 'type of h ', h.dtype.type # prints <type 'numpy.int32'>
print 'type of i ', i.dtype.type # prints <type 'numpy.int32'>
print h.dtype.type == i.dtype.type # prints True
print h.dtype.type == np.int32 # prints False
print i.dtype.type == np.int32 # prints False
print i.dtype.type == np.bool_ # prints False
Seems normal enough to me. Using
np.maximumreturns the maximum ofgand4, which is4(True == 1). You get a matrix full of fours, which is integer type.If you use this syntax for your type comparisons, they work:
h.dtype.type == np.dtype(np.int32)or more simplyh.dtype == np.int32.