cunumeric.ndarray.item#

ndarray.item(*args)#

Copy an element of an array to a standard Python scalar and return it.

Parameters:

*args

  • none: in this case, the method only works for arrays

    with one element (a.size == 1), which element is copied into a standard Python scalar object and returned.

  • int_type: this argument is interpreted as a flat index into

    the array, specifying which element to copy and return.

  • tuple of int_types: functions as does a single int_type

    argument, except that the argument is interpreted as an nd-index into the array.

Returns:

z – A copy of the specified element of the array as a suitable Python scalar

Return type:

scalar

Notes

When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned. item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math.

Availability:

Multiple GPUs, Multiple CPUs