-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Broadcasting does not work with inplace "+=" operator #9031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is by design, because the inplace operators are intended to operate on the same chunk of memory as the input - but the broadcast result would not find in that memory. Having said that, it might be reasonable to allow In your case, the fix is simple - just allocate the arrays to the correct size first - at a guess, that would be:
|
@mratsim Can you give an example of input that triggers this error? When I run your function on NumPy arrays it works properly:
|
I am implementing Welford's algorithm to compute mean and variance on a series of images.
Broadcasting does not work.
The algorithm for scalars courtesy of Wikipedia
For numpy arrays I am forced to replace
mean += delta/n
bymean = mean + delta/n
The error I get is
non-broadcastable output operand with shape () doesn't match the broadcast shape (256,256,3)
. My images have shape 256x256x3 (RGB).The text was updated successfully, but these errors were encountered: