निम्नलिखित कोड का परिणाम क्या है?
What is the output of the following code?
import numpy as np
a = np.array([1,2,3,5,8])
b = np.array([0,1,5,4,2])
c = a + b
c = c*a
print (c[2])
A)
B)
C)
D)
Explanation:
Let's simplify the explanation:
-
Arrays:
a = [1, 2, 3, 5, 8] b = [0, 1, 5, 4, 2]
-
Adding arrays
a
andb
:c = a + b # [1+0, 2+1, 3+5, 5+4, 8+2] = [1, 3, 8, 9, 10]
-
Multiplying
c
bya
:c = c * a # [1*1, 3*2, 8*3, 9*5, 10*8] = [1, 6, 24, 45, 80]
-
Print the third element (
c[2]
):print(c[2]) # This is 24
Output: 24
Answer: (B) 24