Reputation: 61
when I use
from numpy.math import factorial as fact
I get : ImportError: No module named 'numpy.math'
but
import numpy
fact=numpy.math.factorial
works.
Why ? Is numpy.math really implemented like other modules ?
Upvotes: 4
Views: 2267
Reputation: 12410
Arpad Horvath's answer has already shown, that numpy.math
is not different from the math
library and therefore won't work on numpy arrays that can't be converted to scalars. But you can use scipy.misc.factorial
:
import scipy.misc
a = np.arange(5)
print(scipy.misc.factorial(a))
#output
#[ 1. 1. 2. 6. 24.]
This is deprecated in scipy 1.0.0, though still working. Use scipy.special.factorial
instead.
Other mathematical functions implemented for arrays are listed here in numpy
and here in scipy.specials
Upvotes: 2
Reputation: 1882
numpy seems to import the standard math
library:
In [8]: import numpy
In [9]: import math
In [10]: math is numpy.math
Out[10]: True
So it is not the submodule of numpy, just an imported module object. That is why you can not import like this: from numpy.math import something
.
Upvotes: 3