为什么float64在与列表相乘时转换为int?

wer*_*ere 9 python numpy

将numpy浮点数与列表相乘时,float会自动转换为int

>>> import numpy as np
>>> a = [1, 2, 3]
>>> np.float64(2.0) * a ### This behaves as 2 * a
[1, 2, 3, 1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

普通的float给出了一个TypeError

>>> 2.0 * a ### This does not
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
Run Code Online (Sandbox Code Playgroud)

但是,numpy float不能用于索引

>>> a[np.float64(2.0)]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not numpy.float64
Run Code Online (Sandbox Code Playgroud)

这种行为背后的逻辑是什么?

And*_*rew 3

您遇到了 NumPy 中的一个已知错误。GitHub 问题已于去年关闭,但该行为在 NumPy 版本 1.9.1 中仍然存在。