202k views
5 votes
What will be output for the following code? import numpy as np a = np.array([1,2,3,5,8]) b = np.array([0,3,4,2,1]) c = a + b c = c*a print (c[2])

a. 7
b. 12
c. 10
d. 21

1 Answer

2 votes

Final answer:

The output of the given code will be 21.

Step-by-step explanation:

The given code uses NumPy library in Python to perform array operations. The arrays a and b are initialized with values [1, 2, 3, 5, 8] and [0, 3, 4, 2, 1] respectively. The operation c = a + b adds the corresponding elements of a and b resulting in [1+0, 2+3, 3+4, 5+2, 8+1] = [1, 5, 7, 7, 9]. Then, c = c*a multiplies each element of c with the corresponding element of a, resulting in [1*1, 5*2, 7*3, 7*5, 9*8] = [1, 10, 21, 35, 72].

Therefore, the output of print(c[2]) will be 21.

User Knyri
by
9.0k points