问题描述
如何分别从 numpy 和 scipy 导入阶乘函数以查看哪个更快?
How can I import factorial function from numpy and scipy separately in order to see which one is faster?
我已经通过导入数学从 python 本身导入了阶乘.但是,它不适用于 numpy 和 scipy.
I already imported factorial from python itself by import math. But, it does not work for numpy and scipy.
推荐答案
您可以像这样导入它们:
You can import them like this:
In [7]: import scipy, numpy, math
In [8]: scipy.math.factorial, numpy.math.factorial, math.factorial
Out[8]:
(<function math.factorial>,
<function math.factorial>,
<function math.factorial>)
scipy.math.factorial
和 numpy.math.factorial
似乎只是 math.factorial
的别名/引用,即is scipy.math.factorial is math.factorial
和 numpy.math.factorial is math.factorial
都应该给 True
.
scipy.math.factorial
and numpy.math.factorial
seem to simply be aliases/references for/to math.factorial
, that is scipy.math.factorial is math.factorial
and numpy.math.factorial is math.factorial
should both give True
.
这篇关于numpy 和 scipy 中的因子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!