Python | Numpy ndarray.item() (original) (raw)

Last Updated : 27 Mar, 2019

With the help of **numpy.ndarray.item()** method, we can fetch the data elements that is found at the given index on numpy array. Remember we can give index as one dimensional parameter or can be two dimensional.

Parameters:
*args : Arguments (variable number and type)
-> none: This argument only works when size of an array is 1.
-> int_type: This argument is interpreted as a flat index into the array, specifying which element to return.
-> tuple of int_types: This argument is interpreted as a two dimensional array, by specifying which element to return.

Returns: Copy of an Item

Example #1 :
In this example we can see that by specifying the argument in ndarray.item() method, we can have the element if it existed on this index.

import numpy as np

gfg = np.array([ 1 , 2 , 3 , 4 , 5 ])

print (gfg.item( 2 ))

Example #2 :

import numpy as np

gfg = np.array([[ 1 , 2 , 3 , 4 , 5 ],

`` [ 6 , 5 , 4 , 3 , 2 ]])

print (gfg.item(( 1 , 2 )))

Similar Reads