Repository: numpy/numpy
Pull request: DOC: Mention that expand_dims returns a view
<!-- Please be sure you are following the instructions in the dev guidelines
http://www.numpy.org/devdocs/dev/development_workflow.html
-->

<!-- We'd appreciate it if your commit message is properly formatted
http://www.numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message
-->
Fix #11632 by mentioning in the return type that `expand_dims` returns a view.

Problem statement:
DOC: expand_dims returns a view
Hi,

if we apply expand_dims to a numpy array 'a' :
b = numpy.expand_dims(a, axis=0)
the 'b' is not a new array, it will be a link to the objects 'a'

is it correct behavior?
if so, it should be noted in the manual

thanks!

Hints from issue discussion:
Certainly intended. But the documentation could indeed mention that it returns a view (both in the summery and for the return array probably). Want to create a pull request?

Commit message: DOC: Mention that expand_dims returns a view

Patch to review:
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index ac2a2560498b..21070ce36a5b 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -533,7 +533,7 @@ def expand_dims(a, axis):
     -------
     res : ndarray
         Output array. The number of dimensions is one greater than that of
-        the input array.
+        the input array. This is a view on the original array `a`.
 
     See Also
     --------


Code review comments:
diff_hunk: @@ -533,7 +533,7 @@ def expand_dims(a, axis):
     -------
     res : ndarray
         Output array. The number of dimensions is one greater than that of
-        the input array.
+        the input array. This is a view on the original array `a`.
path: numpy/lib/shape_base.py
text: @user1:
Perhaps replace both sentences with "View of `a` with the number of dimensions increased by one"