77 "HasNDim" ,
88 "HasShape" ,
99 "HasSize" ,
10+ "HasTranspose" ,
1011)
1112
1213from types import ModuleType
@@ -157,6 +158,36 @@ def size(self) -> int | None:
157158 ...
158159
159160
161+ class HasTranspose (Protocol ):
162+ """Protocol for array classes that support the transpose operation."""
163+
164+ @property
165+ def T (self ) -> Self : # noqa: N802
166+ """Transpose of the array.
167+
168+ The array instance must be two-dimensional. If the array instance is not
169+ two-dimensional, an error should be raised.
170+
171+ Returns:
172+ Self: two-dimensional array whose first and last dimensions (axes)
173+ are permuted in reverse order relative to original array. The
174+ returned array must have the same data type as the original
175+ array.
176+
177+ Notes:
178+ Limiting the transpose to two-dimensional arrays (matrices) deviates
179+ from the NumPy et al practice of reversing all axes for arrays
180+ having more than two-dimensions. This is intentional, as reversing
181+ all axes was found to be problematic (e.g., conflicting with the
182+ mathematical definition of a transpose which is limited to matrices;
183+ not operating on batches of matrices; et cetera). In order to
184+ reverse all axes, one is recommended to use the functional
185+ `PermuteDims` interface found in this specification.
186+
187+ """
188+ ...
189+
190+
160191class Array (
161192 # ------ Attributes -------
162193 HasDType [DTypeT_co ],
@@ -165,6 +196,7 @@ class Array(
165196 HasNDim ,
166197 HasShape ,
167198 HasSize ,
199+ HasTranspose ,
168200 # ------- Methods ---------
169201 HasArrayNamespace [NamespaceT_co ],
170202 # -------------------------
0 commit comments