🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

निम्नलिखित कोड के लिए आउटपुट क्या होगा?

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:

  1. a and b arrays:

    • a = np.array([1, 2, 1, 5, 8])
    • b = np.array([0, 1, 5, 4, 2])
  2. c = a + b:

    • Element-wise addition of a and b:
    c = [1+0, 2+1, 1+5, 5+4, 8+2]
    c = [1, 3, 6, 9, 10]
    
  3. c = c * a:

    • Element-wise multiplication of c and a:
    c = [1*1, 3*2, 6*1, 9*5, 10*8]
    c = [1, 6, 6, 45, 80]
    
  4. print(c[2]):

    • The third element (index 2) of the array c is 6.

Output:

(A) 6

Latest Updates