dpnp.ndarray.item

method

ndarray.item(*args)

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

For full documentation refer to numpy.ndarray.item.

Parameters:

*args ({none, int, tuple of ints}) --

  • 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: this argument is interpreted as a flat index into the array, specifying which element to copy and return.

  • tuple of ints: functions as does a single int argument, except that the argument is interpreted as an nd-index into the array.

Returns:

out -- A copy of the specified element of the array as a suitable Python scalar.

Return type:

Standard Python scalar object

Examples

>>> import dpnp as np
>>> np.random.seed(123)
>>> x = np.random.randint(9, size=(3, 3))
>>> x
array([[0, 0, 7],
       [6, 6, 6],
       [0, 7, 1]])
>>> x.item(3)
6
>>> x.item(7)
7
>>> x.item((0, 1))
0
>>> x.item((2, 2))
1
>>> x = np.array(5)
>>> x.item()
5