summaryrefslogtreecommitdiff
path: root/numpy/add_newdocs.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-10-05 07:44:00 -0600
committerGitHub <noreply@github.com>2017-10-05 07:44:00 -0600
commit804cb0e7b1b031503fc04e2b6e586804650af5d5 (patch)
tree9460e687d0c3851fba92d5bc745e5c339026f10f /numpy/add_newdocs.py
parent98e7efc12ccbc53bef8b6c4e98354b29dcede3d0 (diff)
parent6a5e6188d938091ca1c335ae5f736b563bdca245 (diff)
downloadnumpy-804cb0e7b1b031503fc04e2b6e586804650af5d5.tar.gz
Merge pull request #9810 from charris/gh-9571
DOC: Improve ndarray.shape documentation.
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r--numpy/add_newdocs.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 55538ad1b..fd6fe277f 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -2926,10 +2926,12 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('shape',
"""
Tuple of array dimensions.
- Notes
- -----
- May be used to "reshape" the array, as long as this would not
- require a change in the total number of elements
+ The shape property is usually used to get the current shape of an array,
+ but may also be used to reshape the array in-place by assigning a tuple of
+ array dimensions to it. As with `numpy.reshape`, one of the new shape
+ dimensions can be -1, in which case its value is inferred from the size of
+ the array and the remaining dimensions. Reshaping an array in-place will
+ fail if a copy is required.
Examples
--------
@@ -2948,6 +2950,15 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('shape',
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: total size of new array must be unchanged
+ >>> np.zeros((4,2))[::2].shape = (-1,)
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ AttributeError: incompatible shape for a non-contiguous array
+
+ See Also
+ --------
+ numpy.reshape : similar function
+ ndarray.reshape : similar method
"""))