Skip to content

Commit

Permalink
DOC: Changed shape assignment example to reshape. Elaborated modifyin…
Browse files Browse the repository at this point in the history
…g shape
  • Loading branch information
petetanru committed Nov 11, 2016
1 parent 0268680 commit 7c784b6
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions doc/source/user/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,28 @@ An array has a shape given by the number of elements along each axis::
>>> a.shape
(3, 4)

The shape of an array can be changed with various commands::
The shape of an array can be changed with various commands. Note that the
following three commands all return a modified array, but do not change
the original array::

>>> a.ravel() # flatten the array
>>> a.ravel() # returns the array, flattened
array([ 2., 8., 0., 6., 4., 5., 1., 1., 8., 9., 3., 6.])
>>> a.shape = (6, 2)
>>> a.T
array([[ 2., 0., 4., 1., 8., 3.],
[ 8., 6., 5., 1., 9., 6.]])
>>> a.reshape(6,2) # returns the array with a modified shape
array([[ 2., 8.],
[ 0., 6.],
[ 4., 5.],
[ 1., 1.],
[ 8., 9.],
[ 3., 6.]])
>>> a.T # returns the array, transposed
array([[ 2., 4., 8.],
[ 8., 5., 9.],
[ 0., 1., 3.],
[ 6., 1., 6.]])
>>> a.T.shape
(4, 3)
>>> a.shape
(3, 4)

The order of the elements in the array resulting from ravel() is
normally "C-style", that is, the rightmost index "changes the fastest",
Expand All @@ -652,12 +666,9 @@ argument with a modified shape, whereas the
itself::

>>> a
array([[ 2., 8.],
[ 0., 6.],
[ 4., 5.],
[ 1., 1.],
[ 8., 9.],
[ 3., 6.]])
array([[ 2., 8., 0., 6.],
[ 4., 5., 1., 1.],
[ 8., 9., 3., 6.]])
>>> a.resize((2,6))
>>> a
array([[ 2., 8., 0., 6., 4., 5.],
Expand Down

0 comments on commit 7c784b6

Please sign in to comment.