Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factorial in numpy and scipy

How can I import factorial function from numpy and scipy separately in order to see which one is faster?

I already imported factorial from python itself by import math. But, it does not work for numpy and scipy.

like image 800
MOON Avatar asked Feb 13 '14 12:02

MOON


People also ask

How do you calculate factorial in Numpy?

The formula for factorial is n! = n(n-1) (n-2) (n-3) .... n . Here n is the number whose factorial is to be calculated. Factorial is the product of integer and all the integers below it.

Does Numpy have a factorial?

It's important to note that the Numpy factorial function (AKA, numpy. math. factorial) only accepts integer values as an input. It will throw an error if you attempt to use this function on a Numpy array.

Does python recognize factorial?

You can implement a factorial function in Python using one of several tools: for loops. Recursive functions. math.


1 Answers

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 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.

like image 66
Ashwini Chaudhary Avatar answered Sep 28 '22 12:09

Ashwini Chaudhary