[NumPy-Tickets] [NumPy] #301: power with negative argument returns 0

NumPy Trac numpy-tickets@scipy....
Sun Aug 8 01:27:30 CDT 2010


#301: power with negative argument returns 0
-------------------------+--------------------------------------------------
 Reporter:  stefan       |       Owner:  somebody      
     Type:  enhancement  |      Status:  needs_decision
 Priority:  normal       |   Milestone:  1.5.0         
Component:  numpy.core   |     Version:                
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by rgommers):

 Would be good to do the same as math.pow. For negative powers you always
 want a float, and this is also what ** does. So that should be fixed
 anyway. Then what's left to decide is if positive powers should return
 float or integer. Since neg powers returns floats it may be better to be
 consistent and do the same for pos powers.
 {{{
 In [13]: math.pow(3, -1)
 Out[13]: 0.33333333333333331

 In [14]: math.pow(3, 1)
 Out[14]: 3.0

 In [15]: math.pow(3, -1)
 Out[15]: 0.33333333333333331

 In [16]: np.power(3, 1)
 Out[16]: 3

 In [17]: np.power(3, -1)
 Out[17]: 0

 In [18]: 3**1
 Out[18]: 3

 In [19]: 3**-1
 Out[19]: 0.33333333333333331
 }}}
 As for ufunc design, sqrt() also gives floats even if ints are possible,
 {{{
 In [21]: np.sqrt(4)
 Out[21]: 2.0
 }}}
 so this is not a big issue I would say.

 For divide(), my vote would be for casting to float too.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/301#comment:6>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list