Python | Numpy ndarray.item()
Last Updated : 27 Mar, 2019
Improve
With the help of Python3 1== Python3 1==
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 ItemExample #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 the important module in python
import numpy as np
# make an array with numpy
gfg = np.array([1, 2, 3, 4, 5])
# applying ndarray.item() method
print(gfg.item(2))
Output:
Example #2 :3
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.array([[1, 2, 3, 4, 5],
[6, 5, 4, 3, 2]])
# applying ndarray.item() method
print(gfg.item((1, 2)))
Output:
4