[SciPy-Dev] factorial2 does not return a float with exact=False

Warren Weckesser warren.weckesser@enthought....
Mon Jun 28 20:24:52 CDT 2010


Vincent Davis wrote:
> On Mon, Jun 28, 2010 at 7:11 PM, Vincent Davis <vincent@vincentdavis.net> wrote:
>   
>> According to the docs factorial2 should return a float or int, float
>> in the case of exact=False, It does not.
>>
>>     
>>>>> import scipy.misc.common as sc
>>>>> sc.factorial2(7, exact=False)
>>>>>           
>> array(105.00000000000001)
>>     
>>>>> sc.factorial2(7, exact=True)
>>>>>           
>> 105L
>>     
>>>>> sc.factorial2(8, exact=True)
>>>>>           
>> 384L
>>     
>>>>> sc.factorial2(8, exact=False)
>>>>>           
>> array(384.0)
>>     
>>>>> sc.factorial2(8, exact=False)
>>>>>           
>
> Same with factorial
>
>   
>>>> sc.factorial(5, exact=False)
>>>>         
> array(120.0)
>   
>>>> arr = np.array([3,4,5])
>>>> sc.factorial(arr, exact=False)
>>>>         
> array([   6.,   24.,  120.])
>   
>>>> sc.factorial(5, exact=True)
>>>>         
> 120L
>   

I think the problem is simply that it is an awkward API.  After looking 
at the code for factorial, a more precise description is:

If `exact` is True, `n` must be an integer, and an integer is returned.

If `exact` is False, `n` is array_like, and an array the same shape as 
`n` is returned.


Warren

> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>   



More information about the SciPy-Dev mailing list