w3resource logo
Python Exercises

Python NumPy: Find the 4th element of a specified array

Python NumPy: Array Object Exercise-50 with Solution

Write a Python program to find the 4th element of a specified array.

Sample Solution :-

Python Code :

import numpy as np
x = np.array([[2, 4, 6], [6, 8, 10]], np.int32)
print(x)
e1 = x.flat[3]
print("Forth e1ement of the array:")
print(e1)

Sample Output:

[[ 2  4  6]                                                            
 [ 6  8 10]]                                                           
Forth e1ement of the array:                                            
6 

Python Code Editor:

import numpy as np
x = np.array([[2, 4, 6], [6, 8, 10]], np.int32)
print(x)
e1 = x.flat[3]
print("Forth e1ement of the array:")
print(e1)

Improve this sample solution and post your code through Disqus