我有下面的python(3)脚本。我有numpy1.13.1(一个旧版本,但是我的问题是
dtype
应该有用)。
根据
this
数据类型存在于
ufunc
从1.6开始
import numpy as np
M=1001
N = 2 ** np.ceil(np.log2(M))
N
Out[252]: 1024.0
2 ** np.ceil(np.log2(M),dtype=int)
Traceback (most recent call last):
File "<ipython-input-253-4b982a04c884>", line 1, in <module>
2 ** np.ceil(np.log2(M),dtype=int)
TypeError: No loop matching the specified signature and casting
was found for ufunc ceil
2 ** np.ceil(np.log2(M),dtype=float)
Out[254]: 1024.0
2 ** np.ceil(np.log2(M),dtype=np.float64)
Out[256]: 1024.0
2 ** np.ceil(np.log2(M),dtype=np.float32)
Out[257]: 1024.0
2 ** np.ceil(np.log2(M),dtype=np.int64)
Traceback (most recent call last):
File "<ipython-input-258-9902fa43f3ac>", line 1, in <module>
2 ** np.ceil(np.log2(M),dtype=np.int64)
TypeError: No loop matching the specified signature and casting
was found for ufunc ceil
2 ** np.ceil(np.log2(M),dtype=np.int32)
Traceback (most recent call last):
File "<ipython-input-259-8a2f2834384f>", line 1, in <module>
2 ** np.ceil(np.log2(M),dtype=np.int32)
TypeError: No loop matching the specified signature and casting
was found for ufunc ceil
你看我换衣服的时候
数据类型
到
int
int32
int64
它失败了。可能除了
float
失败。我想这不应该这样!
我可以加一个小补丁
int(np.ceil(...))
结果就是我想要的。
-
numpy reference ceil
).
-
谢谢