8000 DOC: clarify documentation for transpose() by danpovey · Pull Request #15024 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: clarify documentation for transpose() #15024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
DOC: Improve documentation for transpose()
  • Loading branch information
danpovey committed Dec 2, 2019
commit 9bf03f6f829a06f2e5bcaf17345d78bb6162107f
21 changes: 13 additions & 8 deletions numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,20 @@ def _transpose_dispatcher(a, axes=None):
@array_function_dispatch(_transpose_dispatcher)
def transpose(a, axes=None):
"""
Permute the dimensions of an array.
Reverse or permute the axes of an array; returns the modified array.
For an array a with two axes, transpose(a) gives the matrix transpose
of a.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PEP257 needs a blank line before this sentence.

Suggested change
For an array a with two axes, transpose(a) gives the matrix transpose
of a.
For an array ``a`` with two axes, ``transpose(a)`` gives the matrix transpose
of a.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still applies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed fix


Parameters
----------
a : array_like
Input array.
axes : list of ints, optional
By default, reverse the dimensions, otherwise permute the axes
according to the values given.
axes : tuple or list of ints, optional
If not specified, this function reverses the order of the axes.
If specified, it must be a tuple, list or similar object which contains
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"similar object", is typically called "sequence" in python language. In fact, tuple or list can probably also be replaced with sequence. Unless we want to nudge people towards tuple specifically (since in many cases axes has to be a tuple).

Looks good to me.

8000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would lean towards documenting it as just tuple or list, and not encouraging users to to pass anything else.

a permutation of [0,1,..,N-1] where N is the number of axes of a. The
i'th axis of the returned array will correspond to the axis numbered
axes[i] of the input.

Returns
-------
Expand Down Expand Up @@ -797,7 +802,7 @@ def argpartition(a, kth, axis=-1, kind='introselect', order=None):
partition : Describes partition algorithms used.
ndarray.partition : Inplace partition.
argsort : Full indirect sort.
take_along_axis : Apply ``index_array`` from argpartition
take_along_axis : Apply ``index_array`` from argpartition
to an array as if by calling partition.

Notes
Expand Down Expand Up @@ -1039,7 +1044,7 @@ def argsort(a, axis=-1, kind=None, order=None):
lexsort : Indirect stable sort with multiple keys.
ndarray.sort : Inplace sort.
argpartition : Indirect partial sort.
take_along_axis : Apply ``index_array`` from argsort
take_along_axis : Apply ``index_array`` from argsort
to an array as if by calling sort.

Notes
Expand Down Expand Up @@ -1136,7 +1141,7 @@ def argmax(a, axis=None, out=None):
ndarray.argmax, argmin
amax : The maximum value along a given axis.
unravel_index : Convert a flat index into an index tuple.
take_along_axis : Apply ``np.expand_dims(index_array, axis)``
take_along_axis : Apply ``np.expand_dims(index_array, axis)``
from argmax to an array as if by calling max.

Notes
Expand Down Expand Up @@ -1217,7 +1222,7 @@ def argmin(a, axis=None, out=None):
ndarray.argmin, argmax
amin : The minimum value along a given axis.
unravel_index : Convert a flat index into an index tuple.
take_along_axis : Apply ``np.expand_dims(index_array, axis)``
take_along_axis : Apply ``np.expand_dims(index_array, axis)``
from argmin to an array as if by calling min.

Notes
Expand Down
0