In questo caso, perché x += y
produce un risultato diverso da x = x + y
?Numpy, perché `x + = y` produce un risultato diverso da` x = x + y`?
import numpy as np
x = np.repeat([1], 10)
y = np.random.random(len(x))
x += y
print x
# Output: [1 1 1 1 1 1 1 1 1 1]
x = x + y
print x
# Output: [ 1.50859536 1.31434732 1.15147365 1.76979431 1.64727364
# 1.02372535 1.39335253 1.71878847 1.48823703 1.99458116]
In effetti un duplicato. Risposta breve: dipende dall'implementazione dei metodi "dunder" magici '__add__' e' __iadd__' –
** Questo non è un duplicato **, questo è specifico per 'numpy' – jamylak
@jamylak Oh - anzi, buona cattura, Grazie! –