Skip to content
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

Merged
merged 1 commit into from Nov 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

@mbauman mbauman Sep 13, 2018

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 side X must be an array with the same shape* as the result of indexing A[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 in X 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.

the indices: `prod(length(I_1), length(I_2), ..., length(I_n))`. The value in location `I_1[i_1], I_2[i_2], ..., I_n[i_n]`
of `A` is overwritten with the value `X[i_1, i_2, ..., i_n]`. If `X` is not an array, its value
is written to all referenced locations of `A`.
of `A` is overwritten with the value `X[i_1, i_2, ..., i_n]`. If `X` is a scalar, use the
element-wise assignment operator `.=` to write the value to all referenced locations of `A`:
This conversation was marked as resolved.
Show resolved Hide resolved

```
A[I_1, I_2, ..., I_n] .= X
```

Just as in [Indexing](@ref man-array-indexing), the `end` keyword may be used
to represent the last index of each dimension within the indexing brackets, as
Expand Down