निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([1,2,1,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 break down the code step by step:
import numpy as np
a = np.array([1, 2, 1, 5, 8])
b = np.array([0, 1, 5, 4, 2])
c = a + b # Element-wise addition of a and b
c = c * a # Element-wise multiplication of c and a
print(c[2]) # Print the third element of array c
Step-by-Step Explanation:
-
a
andb
arrays:a = np.array([1, 2, 1, 5, 8])
b = np.array([0, 1, 5, 4, 2])
-
c = a + b
:- Element-wise addition of
a
andb
:
c = [1+0, 2+1, 1+5, 5+4, 8+2] c = [1, 3, 6, 9, 10]
- Element-wise addition of
-
c = c * a
:- Element-wise multiplication of
c
anda
:
c = [1*1, 3*2, 6*1, 9*5, 10*8] c = [1, 6, 6, 45, 80]
- Element-wise multiplication of
-
print(c[2])
:- The third element (index 2) of the array
c
is6
.
- The third element (index 2) of the array
Output:
(A) 6