@@ -151,6 +151,36 @@ def size(self) -> int | None:
151151 ...
152152
153153
154+ class HasTranspose (Protocol ):
155+ """Protocol for array classes that support the transpose operation."""
156+
157+ @property
158+ def T (self ) -> Self : # noqa: N802
159+ """Transpose of the array.
160+
161+ The array instance must be two-dimensional. If the array instance is not
162+ two-dimensional, an error should be raised.
163+
164+ Returns:
165+ Self: two-dimensional array whose first and last dimensions (axes)
166+ are permuted in reverse order relative to original array. The
167+ returned array must have the same data type as the original
168+ array.
169+
170+ Notes:
171+ Limiting the transpose to two-dimensional arrays (matrices) deviates
172+ from the NumPy et al practice of reversing all axes for arrays
173+ having more than two-dimensions. This is intentional, as reversing
174+ all axes was found to be problematic (e.g., conflicting with the
175+ mathematical definition of a transpose which is limited to matrices;
176+ not operating on batches of matrices; et cetera). In order to
177+ reverse all axes, one is recommended to use the functional
178+ `PermuteDims` interface found in this specification.
179+
180+ """
181+ ...
182+
183+
154184class Array (
155185 # ------ Attributes -------
156186 HasDType [DTypeT_co ],
@@ -159,6 +189,7 @@ class Array(
159189 HasNDim ,
160190 HasShape ,
161191 HasSize ,
192+ HasTranspose ,
162193 # ------- Methods ---------
163194 HasArrayNamespace [NamespaceT_co ],
164195 # -------------------------
0 commit comments