We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 15af431 commit 8e84d60Copy full SHA for 8e84d60
arrayfire/array.py
@@ -1253,6 +1253,19 @@ def to_list(self, row_major=False):
1253
ct_array, shape = self.to_ctype(row_major, True)
1254
return _ctype_to_lists(ct_array, len(shape) - 1, shape)
1255
1256
+ def scalar(self):
1257
+ """
1258
+ Return the first element of the array
1259
1260
+
1261
+ if (self.arr.value == 0):
1262
+ raise RuntimeError("Can not call to_ctype on empty array")
1263
1264
+ ctype_type = to_c_type[self.type()]
1265
+ res = ctype_type()
1266
+ safe_call(backend.get().af_get_scalar(c_pointer(res), self.arr))
1267
+ return res.value
1268
1269
def __str__(self):
1270
"""
1271
Converts the arrayfire array to string showing its meta data and contents.
0 commit comments