diff options
author | Ian Sanders <iansan5653@gmail.com> | 2019-02-22 14:00:16 -0500 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2019-02-22 20:00:16 +0100 |
commit | 04b422017008bb24713475b85c072395dce89059 (patch) | |
tree | 829933eed8e499f67e49da83a35d295664461958 | |
parent | 67e20d09d3d83eed4c8ce06cf5d5dd6e0b38b856 (diff) | |
download | numpy-04b422017008bb24713475b85c072395dce89059.tar.gz |
DOC: Recommend adding dimension to switch between row and column vectors (#12973)
* DOC: Recommend using reshape instead of matrix for vector transpose
* Rephrase doc advice for 1-D vector transpose
Recommend adding a dimension instead of using `reshape`.
Per @eric-wieser, makes explanation more technical.
* Fix grammar
-rw-r--r-- | numpy/core/_add_newdocs.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index 159da0121..9cc8f562a 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -4145,9 +4145,11 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('transpose', Returns a view of the array with axes transposed. - For a 1-D array, this has no effect. (To change between column and - row vectors, first cast the 1-D array into a matrix object.) - For a 2-D array, this is the usual matrix transpose. + For a 1-D array this has no effect, as a transposed vector is simply the + same vector. To convert a 1-D array into a 2D column vector, an additional + dimension must be added. `np.atleast2d(a).T` achieves this, as does + `a[:, np.newaxis]`. + For a 2-D array, this is a standard matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided and ``a.shape = (i[0], i[1], ... i[n-2], i[n-1])``, then @@ -4173,6 +4175,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('transpose', See Also -------- ndarray.T : Array property returning the array transposed. + ndarray.reshape : Give a new shape to an array without changing its data. Examples -------- |