[Numpy-discussion] numpy type mismatch

Pauli Virtanen pav@iki...
Fri Jun 10 21:03:53 CDT 2011


On Fri, 10 Jun 2011 18:51:14 -0700, Keith Goodman wrote:
[clip]
> Maybe this is the same question, but are you maybe yes, maybe no on this
> too:
> 
>     >>> type(np.sum([1, 2, 3], dtype=np.int32)) == np.int32
>     False

Note that this is a comparison between two Python types...

> Ben, what happens if you put an axis in there? Like
> 
>     >>> np.sum([[1, 2, 3], [4,5,6]], axis=0).dtype == np.int32
> 
> Just wondering if this is another different-dtype-for-different-axis
> case.

... and this between Numpy dtypes (the RHS operand is cast to a dtype).

The confusion comes from the fact that Numpy registers two Python types,
one of them corresponding to 'l' and one to 'i', but both print as "int32"
so it's difficult to tell which one you have. They behave exactly the same
way everywhere, except that they do not compare equal...



More information about the NumPy-Discussion mailing list