Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2e4034

Browse files
committed
Provide fix guidance
1 parentbc88f60 commitd2e4034

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
* ``arr.T`` property has been deprecated for array scalars and arrays with
2-
dimensionality different than ``2``.
1+
* ``arr.T`` property has been deprecated for array scalars and arrays with dimensionality
2+
different than ``2`` to be compatible with the Array API standard. To achieve the same
3+
behavior when ``arr.ndim != 2``, either ``np.permute_dims(arr, range(arr.ndim)[::-1])``
4+
(also compatible with the Array API) or ``arr.transpose()`` can be used.

‎numpy/_core/src/multiarray/getset.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,10 @@ array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
852852
if (ndim!=2) {
853853
if (PyErr_WarnFormat(PyExc_UserWarning,1,
854854
"In the future `.T` property will be supported for "
855-
"2-dim arrays only. Here it is %d-dim array.",
855+
"2-dim arrays only. Received %d-dim array. Either "
856+
"`np.permute_dims(arr, range(arr.ndim)[::-1])` "
857+
"(compatible with the Array API) or `arr.transpose()` "
858+
"should be used instead.",
856859
ndim)<0) {
857860
returnNULL;
858861
}

‎numpy/_core/src/multiarray/scalartypes.c.src

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,11 @@ gentype_transpose_get(PyObject *self, void *NPY_UNUSED(ignored))
19271927
{
19281928
if (PyErr_WarnEx(PyExc_UserWarning,
19291929
"In the future `.T` property for array scalars will "
1930-
"raise an error.",1)<0) {
1930+
"raise an error. If you call `.T` on an array scalar "
1931+
"intentionally you can safely drop it. In other cases "
1932+
"`np.permute_dims(arr, range(arr.ndim)[::-1])` "
1933+
"(compatible with the Array API) or `arr.transpose()` "
1934+
"should be used instead.",1)<0) {
19311935
returnNULL;
19321936
}
19331937
Py_INCREF(self);

‎numpy/_core/tests/test_deprecations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,5 @@ def test_deprecated_T_non_2dim():
464464
UserWarning,
465465
match="In the future `.T` property will be "
466466
"supported for 2-dim arrays only. "
467-
f"Here it is{len(shape)}-dim array."):
467+
f"Received{len(shape)}-dim array."):
468468
np.ones(shape).T

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp