निम्नलिखित कोड के लिए आउटपुट क्या होगा?
What will be output for the following code ?
import numpy as np
a = np.array([1,2,3,5,8])
print (a.ndim) A
0
B
1
C
2
D
3
Explanation
Let's break down the code:
import numpy as np
a = np.array([1, 2, 3, 5, 8])
print(a.ndim)
ais a 1-dimensional numpy array because it's a single list[1, 2, 3, 5, 8].- The
.ndimattribute of a numpy array tells us the number of dimensions of the array.
For the array a = np.array([1, 2, 3, 5, 8]), it is 1D.
So, the output will be 1.
Answer: (B) 1.
Correct Answer: B) 1