[NumPy-Tickets] [NumPy] #1549: base_repr(243, 3) returns '30000'

NumPy Trac numpy-tickets@scipy....
Sat Jul 24 06:47:29 CDT 2010


#1549: base_repr(243, 3) returns '30000'
------------------------+---------------------------------------------------
 Reporter:  kmaglione   |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  2.0.0   
Component:  numpy.core  |     Version:          
 Keywords:              |  
------------------------+---------------------------------------------------

Comment(by kmaglione):

 Sorry, you're right. I meant 243/3**5. For what it's worth, the following
 returns the correct answer, and 5 times faster:

 {{{
 #!python
 def base_repr(num, base, padding=0):
     digits='0123456789abcdef'
     s=[]
     while num:
         s.append(digits[num % base])
         num /= base
     res = ''.join(reversed(s or '0'))
     if padding:
         res = '0' * padding + res
     return res
 }}}

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


More information about the NumPy-Tickets mailing list