-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Update arrays.md for element-wise assignment #29167
Conversation
When assigning a scalar to multiple array values, the `.=` operator is required. The **Assignment** section is updated to reflect this.
Oh, wonderful catch, thank you! Yes, this needs to be changed. The tricky thing about describing this behavior in this section is that it depends upon the broadcasting shape of both sides of the |
@@ -424,8 +424,12 @@ subsections, and arrays of booleans to select elements at their `true` indices. | |||
|
|||
If `X` is an array, it must have the same number of elements as the product of the lengths of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also invert the If-clause here and tighten up this description while we're at it. Maybe something like:
If any index
I_k
selects more than one location, then the right hand sideX
must be an array with the same shape* as the result of indexingA[I_1, I_2, ..., I_n]
or a vector with the same number of elements.
This could lead to a slightly different wording than what you proposed:
The dotted assignment operator
.=
can be used to broadcast the assignment of fewer elements inX
across a compatible shape selected by the indices[I_1, I_2, …, I_n]
.
What do you think? Edit: I actually think what you first wrote about broadcasting might be better.
* That's still not quite true as we also allow adding or removing singleton dimensions to make the shapes match, but this is definitely more accurate than what was there before and I find that extra condition quite confusing to explain.
Can we merge this as an incremental improvement? @mbauman |
Definitely an improvement! Thanks @anders-dc. |
More carefully explain the scalar case, and lead with the shape of the indices to drive the discussion
* Followup to #29167. More carefully explain the scalar case, and lead with the shape of the indices to drive the discussion
When assigning a scalar to multiple array values, the
.=
operator is required. The Assignment section is updated to reflect this.