निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
ary = np.array([1,2,3,5,8])
ary = ary + 1
print (ary[1]) A
0
B
1
C
2
D
3
Explanation
Let's analyze the code:
import numpy as np
ary = np.array([1, 2, 3, 5, 8])
ary = ary + 1
print(ary[1])
Step-by-step breakdown:
ary = np.array([1, 2, 3, 5, 8]): Creates a NumPy array with elements[1, 2, 3, 5, 8].ary = ary + 1: Adds1to each element of the array. This will give[2, 3, 4, 6, 9].print(ary[1]): Prints the element at index1of the modified array, which is3.
So, the output will be:
3
Answer: (D) 3.
Correct Answer: D) 3