diff --git a/arkouda/numpy/__init__.py b/arkouda/numpy/__init__.py index 5cb6627da7..c68ffe93e7 100644 --- a/arkouda/numpy/__init__.py +++ b/arkouda/numpy/__init__.py @@ -96,4 +96,6 @@ from arkouda.numpy.rec import * from ._numeric import * +from ._from_numeric import * from ._manipulation_functions import * + diff --git a/arkouda/numpy/_from_numeric.py b/arkouda/numpy/_from_numeric.py new file mode 100644 index 0000000000..12f61505e7 --- /dev/null +++ b/arkouda/numpy/_from_numeric.py @@ -0,0 +1,44 @@ +from arkouda.numpy.dtypes import isSupportedNumber, numeric_scalars +from arkouda.pdarrayclass import pdarray +from typing import Union, Tuple + +__all__ = ["shape"] + + +def shape(a: Union[pdarray, numeric_scalars]) -> Tuple: + """ + Return the shape of an array. + + Parameters + ---------- + a : pdarray + Input array. + + Returns + ------- + shape : tuple of ints + The elements of the shape tuple give the lengths of the + corresponding array dimensions. + + Examples + -------- + >>> import arkouda as ak + >>> ak.shape(ak.eye(3,2)) + (3, 2) + >>> ak.shape([[1, 3]]) + (1, 2) + >>> ak.shape([0]) + (1,) + >>> ak.shape(0) + () + + """ + if isSupportedNumber(a): + return () + try: + result = a.shape + except AttributeError: + from arkouda import array + + result = array(a).shape + return result diff --git a/tests/numpy/from_numeric_test.py b/tests/numpy/from_numeric_test.py new file mode 100644 index 0000000000..626c0a2f98 --- /dev/null +++ b/tests/numpy/from_numeric_test.py @@ -0,0 +1,15 @@ +import pytest + +import arkouda as ak + + +class TestFromNumericFunctions: + + def test_shape(self): + assert ak.shape([[1, 3]]) == (1, 2) + assert ak.shape([0]) == (1,) + assert ak.shape(0) == () + + @pytest.mark.skip_if_max_rank_less_than(2) + def test_shape_multidim(self): + assert ak.shape(ak.eye(3, 2)) == (3, 2)