Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/source/api-reference/array-manipulation-routines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Transpose-like operations
:toctree: generated/

swapaxes
ndarray.T
BlockArray.T
transpose

Changing number of dimensions
Expand Down
24 changes: 21 additions & 3 deletions nums/core/array/blockarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down