Skip to content

DOC: clarify numpy.asarray parameter 'order' meanings #29571

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
12 changes: 6 additions & 6 deletions numpy/_core/_add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,12 @@
dtype : data-type, optional
By default, the data-type is inferred from the input data.
order : {'C', 'F', 'A', 'K'}, optional
Memory layout. 'A' and 'K' depend on the order of input array a.
'C' row-major (C-style),
'F' column-major (Fortran-style) memory representation.
'A' (any) means 'F' if `a` is Fortran contiguous, 'C' otherwise
'K' (keep) preserve input order
Defaults to 'K'.
The memory layout of the output ndarray. The output of 'A' and 'K' depend on the memory layout of input a.
Copy link
Member

Choose a reason for hiding this comment

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

How about simplifying this to

Suggested change
The memory layout of the output ndarray. The output of 'A' and 'K' depend on the memory layout of input a.
The memory layout of the output.

and move the explanation of the input-dependence of A and K to the individual explanations of A and K below?

'C' gives a row-major layout (C-style),
'F' gives a column-major layout (Fortran-style).
Both 'C' and 'F' ensure a contiguous result.
'A' (any) is equivalent to 'F' if input a is non-contiguous or Fortran-contiguous, otherwise, it is equivalent to 'C'. If the desired output is a non-contiguous Fortran-style ndarray, the user should set ``copy`` to ``True`` to ensure this.
Copy link
Member

Choose a reason for hiding this comment

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

Can we please just add a minimal thing that 'A', like 'K', will not copy to ensure a contiguous output?
Yeah, maybe still confusing, so mentioning the opposite that 'C' and 'F' will copy if needed is maybe clarifying.

'K' (keep) is the default and preserves the input order for the output.
device : str, optional
The device on which to place the created array. Default: ``None``.
For Array-API interoperability only, so must be ``"cpu"`` if passed.
Expand Down
Loading