[Numpy-discussion] Integers to integer powers

R Schumacher rays at blue-cove.com
Tue May 24 16:33:20 EDT 2016


At 01:15 PM 5/24/2016, you wrote:
>On 5/24/2016 3:57 PM, Eric Moore wrote:
>>Changing np.arange(10)**3 to have a non-integer dtype seems like a 
>>big change.
>
>
>What about np.arange(100)**5?

Interesting, one warning per instantiation (Py2.7):

 >>> import numpy
 >>> a=numpy.arange(100)**5
<string>:1: RuntimeWarning: invalid value encountered in power
 >>> a=numpy.arange(100)**5.
 >>> b=numpy.arange(100.)**5
 >>> a==b
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True,  True,
         True,  True,  True,  True,  True,  True,  True,  True, 
True,  True], dtype=bool)
 >>> numpy.arange(100)**5
array([          0,           1,          32,         243,        1024,
               3125,        7776,       16807,       32768,       59049,
             100000,      161051,      248832,      371293,      537824,
             759375,     1048576,     1419857,     1889568,     2476099,
            3200000,     4084101,     5153632,     6436343,     7962624,
            9765625,    11881376,    14348907,    17210368,    20511149,
           24300000,    28629151,    33554432,    39135393,    45435424,
           52521875,    60466176,    69343957,    79235168,    90224199,
          102400000,   115856201,   130691232,   147008443,   164916224,
          184528125,   205962976,   229345007,   254803968,   282475249,
          312500000,   345025251,   380204032,   418195493,   459165024,
          503284375,   550731776,   601692057,   656356768,   714924299,
          777600000,   844596301,   916132832,   992436543,  1073741824,
         1160290625,  1252332576,  1350125107,  1453933568,  1564031349,
         1680700000,  1804229351,  1934917632,  2073071593, -2147483648,
        -2147483648, -2147483648, -2147483648, -2147483648, -2147483648,
        -2147483648, -2147483648, -2147483648, -2147483648, -2147483648,
        -2147483648, -2147483648, -2147483648, -2147483648, -2147483648,
        -2147483648, -2147483648, -2147483648, -2147483648, -2147483648,
        -2147483648, -2147483648, -2147483648, -2147483648, -2147483648])
 >>>
 >>> numpy.arange(100, dtype=numpy.int64)**5
array([         0,          1,         32,        243,       1024,
              3125,       7776,      16807,      32768,      59049,
            100000,     161051,     248832,     371293,     537824,
            759375,    1048576,    1419857,    1889568,    2476099,
           3200000,    4084101,    5153632,    6436343,    7962624,
           9765625,   11881376,   14348907,   17210368,   20511149,
          24300000,   28629151,   33554432,   39135393,   45435424,
          52521875,   60466176,   69343957,   79235168,   90224199,
         102400000,  115856201,  130691232,  147008443,  164916224,
         184528125,  205962976,  229345007,  254803968,  282475249,
         312500000,  345025251,  380204032,  418195493,  459165024,
         503284375,  550731776,  601692057,  656356768,  714924299,
         777600000,  844596301,  916132832,  992436543, 1073741824,
        1160290625, 1252332576, 1350125107, 1453933568, 1564031349,
        1680700000, 1804229351, 1934917632, 2073071593, 2219006624,
        2373046875, 2535525376, 2706784157, 2887174368, 3077056399,
        3276800000, 3486784401, 3707398432, 3939040643, 4182119424,
        4437053125, 4704270176, 4984209207, 5277319168, 5584059449,
        5904900000, 6240321451, 6590815232, 6956883693, 7339040224,
        7737809375, 8153726976, 8587340257, 9039207968, 9509900499], 
dtype=int64) 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160524/57aca92a/attachment.html>


More information about the NumPy-Discussion mailing list