[Numpy-discussion] Multiplying numpy floats and python lists

Pauli Virtanen pav@iki...
Sun Jun 20 13:28:53 CDT 2010


su, 2010-06-20 kello 13:56 -0400, Tony S Yu kirjoitti:
> I came across some strange behavior when multiplying numpy floats and
> python lists: the list is returned unchanged:
> 
> > In [18]: np.float64(1.2) * [1, 2]
> > 
> > Out[18]: [1, 2]

Probably a bug, it seems to round the result first to an integer, and
then do the usual Python thing (try for example np.float64(2.2)).

I'd suggest filing a bug ticket.

Looking at CPython source code, the issue seems to be that np.float64
for some reason passes PyIndex_Check.

But (without whipping out gdb) I can't understand how this can be: the
float64 scalar type is not supposed to have a non-NULL in the nb_index
slot. Indeed, a np.float64.__index__ method does not exist, and the
following indeed does not work:

	[1, 2, 3][np.float64(2.2)]

Strange.

-- 
Pauli Virtanen



More information about the NumPy-Discussion mailing list