निम्नलिखित कोड के लिए आउटपुट क्या होगा?
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)
B)
C)
D)
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
: Adds1
to each element of the array. This will give[2, 3, 4, 6, 9]
.print(ary[1])
: Prints the element at index1
of the modified array, which is3
.
So, the output will be:
3
Answer: (D) 3.