Is there a data type rule on 'x+=' and 'x0=x+'?

Robert rxjwg98 at gmail.com
Wed Dec 9 16:57:54 EST 2015


Hi,

I have a numpy np.array data x:

x= np.array([[157, 185], [169, 195], [162, 179], [145, 195], [159, 199],
 [165, 180], [172, 195], [180, 201], [163, 195], [169, 191]])

Here is the original code snippet:

x+=uniform(-8, 8, x.shape)

x
Out[557]: 
array([[163, 192],
       [163, 187],
       [171, 200],
       [165, 186],
       [162, 185],
       [160, 193],
       [156, 194],
       [168, 197],
       [186, 207],
       [184, 208]])


I am curious about the integer data type of result x.
When I use this code:

x0=x+uniform(-8, 8, x.shape)

x0 is a floating format:

x0
Out[555]: 
array([[ 150.84633535,  188.93254259],
       [ 170.29185044,  197.22753051],
       [ 175.65371771,  190.59168953],
       [ 159.61401655,  175.06364015],
       [ 168.35531363,  180.19243277],
       [ 163.79970077,  206.28600694],
       [ 157.89342616,  203.39444556],
       [ 179.86956647,  192.91265609],
       [ 182.48075601,  208.02397713],
       [ 187.59332123,  207.41482024]])


I would like to know what rule makes these two different result formats.

Could you help me?

Thanks,



More information about the Python-list mailing list