Skip to content

Commit 50400fb

Browse files
dkarraschvtjnashmcabbott
authored
Doc: Mention that dropdims'ed array shares memory (#40544)
Co-authored-by: Jameson Nash <vtjnash@gmail.com> Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
1 parent 7fe05db commit 50400fb

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

base/abstractarraymath.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ _sub(t::Tuple, s::Tuple) = _sub(tail(t), tail(s))
4848
"""
4949
dropdims(A; dims)
5050
51-
Remove the dimensions specified by `dims` from array `A`.
52-
Elements of `dims` must be unique and within the range `1:ndims(A)`.
53-
`size(A,i)` must equal 1 for all `i` in `dims`.
51+
Return an array with the same data as `A`, but with the dimensions specified by
52+
`dims` removed. `size(A,d)` must equal 1 for every `d` in `dims`,
53+
and repeated dimensions or numbers outside `1:ndims(A)` are forbidden.
54+
55+
The result shares the same underlying data as `A`, such that the
56+
result is mutable if and only if `A` is mutable, and setting elements of one
57+
alters the values of the other.
5458
5559
See also: [`reshape`](@ref), [`vec`](@ref).
5660
@@ -62,11 +66,17 @@ julia> a = reshape(Vector(1:4),(2,2,1,1))
6266
1 3
6367
2 4
6468
65-
julia> dropdims(a; dims=3)
69+
julia> b = dropdims(a; dims=3)
6670
2×2×1 Array{Int64, 3}:
6771
[:, :, 1] =
6872
1 3
6973
2 4
74+
75+
julia> b[1,1,1] = 5; a
76+
2×2×1×1 Array{Int64, 4}:
77+
[:, :, 1, 1] =
78+
5 3
79+
2 4
7080
```
7181
"""
7282
dropdims(A; dims) = _dropdims(A, dims)

0 commit comments

Comments
 (0)