diff --git a/docs/source/api-reference/array-manipulation-routines.rst b/docs/source/api-reference/array-manipulation-routines.rst index 25c0a856..d71fcc38 100644 --- a/docs/source/api-reference/array-manipulation-routines.rst +++ b/docs/source/api-reference/array-manipulation-routines.rst @@ -24,7 +24,7 @@ Transpose-like operations :toctree: generated/ swapaxes - ndarray.T + BlockArray.T transpose Changing number of dimensions diff --git a/nums/core/array/blockarray.py b/nums/core/array/blockarray.py index 40277e99..6b80097d 100644 --- a/nums/core/array/blockarray.py +++ b/nums/core/array/blockarray.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +from __future__ import annotations import warnings import itertools @@ -247,14 +247,32 @@ def transpose(self, defer=False, redistribute=False): ) return rarrT + @property + def T(self) -> BlockArray: + """The transposed array. + + Examples: + >>> x = nps.array([[1., 2.], [3., 4.]]) + >>> x.get() + array([[1., 2.], + [3., 4.]]) + >>> x.T.get() + array([[1., 3.], + [2., 4.]]) + >>> x = np.array([1., 2., 3., 4.]) + >>> x.get() + array([1., 2., 3., 4.]) + >>> x.T.get() + array([1., 2., 3., 4.]) + """ + return self.transpose() + def __getattr__(self, item): if item == "__array_priority__" or item == "__array_struct__": # This is triggered by a numpy array on the LHS. raise TypeError("Unexpected conversion attempt from BlockArray to ndarray.") elif item == "ndim": return len(self.shape) - elif item == "T": - return self.transpose() else: raise NotImplementedError(item)