diff --git a/python/src/array.cpp b/python/src/array.cpp index 74223cdda..2580de0ea 100644 --- a/python/src/array.cpp +++ b/python/src/array.cpp @@ -510,6 +510,14 @@ void init_array(py::module_& m) { "size", &array::size, R"pbdoc(Number of elments in the array.)pbdoc") .def_property_readonly( "ndim", &array::ndim, R"pbdoc(The array's dimension.)pbdoc") + .def_property_readonly( + "itemsize", + &array::itemsize, + R"pbdoc(The size of the array's datatype in bytes.)pbdoc") + .def_property_readonly( + "nbytes", + &array::nbytes, + R"pbdoc(The number of bytes in the array.)pbdoc") // TODO, this makes a deep copy of the shape // implement alternatives to use reference // https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html diff --git a/python/tests/test_array.py b/python/tests/test_array.py index fb6a24cbc..847d6d142 100644 --- a/python/tests/test_array.py +++ b/python/tests/test_array.py @@ -84,6 +84,8 @@ def test_array_basics(self): x = mx.array(1) self.assertEqual(x.size, 1) self.assertEqual(x.ndim, 0) + self.assertEqual(x.itemsize, 4) + self.assertEqual(x.nbytes, 4) self.assertEqual(x.shape, []) self.assertEqual(x.dtype, mx.int32) self.assertEqual(x.item(), 1)