diff options
author | Kirill Balunov <kirill.balunov@gmail.com> | 2017-02-07 22:53:23 +0300 |
---|---|---|
committer | Kirill Balunov <kirill.balunov@gmail.com> | 2017-02-07 22:53:23 +0300 |
commit | 40ce834f854827b39c98a6e32d061195edad6662 (patch) | |
tree | b035d961103dfe3fb80953cf9707d3217adb820f /doc | |
parent | b286fd47e9e8d9fd418dc37156d57a58f0637b1d (diff) | |
download | numpy-40ce834f854827b39c98a6e32d061195edad6662.tar.gz |
DOC: fix typo in 'Stacking together different arrays'
The example with `newaxis` now looks rather silly. I left it
because it is the only place in this tutorial with an example
how to use `newaxis`.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/user/quickstart.rst | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/doc/source/user/quickstart.rst b/doc/source/user/quickstart.rst index 65840c724..f69eb3ace 100644 --- a/doc/source/user/quickstart.rst +++ b/doc/source/user/quickstart.rst @@ -713,27 +713,32 @@ Several arrays can be stacked together along different axes:: The function `column_stack` stacks 1D arrays as columns into a 2D array. It is equivalent to -`vstack` only for 1D arrays:: +`hstack` only for 2D arrays:: >>> from numpy import newaxis - >>> np.column_stack((a,b)) # With 2D arrays + >>> np.column_stack((a,b)) # with 2D arrays array([[ 8., 8., 1., 8.], [ 0., 0., 0., 4.]]) >>> a = np.array([4.,2.]) - >>> b = np.array([2.,8.]) - >>> a[:,newaxis] # This allows to have a 2D columns vector + >>> b = np.array([3.,8.]) + >>> np.column_stack((a,b)) # returns a 2D array + array([[ 4., 3.], + [ 2., 8.]]) + >>> np.hstack((a,b)) # the result is different + array([ 4., 2., 3., 8.]) + >>> a[:,newaxis] # this allows to have a 2D columns vector array([[ 4.], [ 2.]]) >>> np.column_stack((a[:,newaxis],b[:,newaxis])) - array([[ 4., 2.], + array([[ 4., 3.], + [ 2., 8.]]) + >>> np.hstack((a[:,newaxis],b[:,newaxis])) # the result is the same + array([[ 4., 3.], [ 2., 8.]]) - >>> np.vstack((a[:,newaxis],b[:,newaxis])) # The behavior of vstack is different - array([[ 4.], - [ 2.], - [ 2.], - [ 8.]]) -For arrays of with more than two dimensions, +On the other hand, the function `row_stack` is equivalent to `vstack` +for any input arrays. +In general, for arrays of with more than two dimensions, `hstack` stacks along their second axes, `vstack` stacks along their first axes, and `concatenate` |