निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
import numpy as np
a = np.array([1.1,2,3])
print(a.dtype)
A)
B)
C)
D)
Explanation:
Let's break down the code:
import numpy as np
a = np.array([1.1, 2, 3])
print(a.dtype)
Explanation:
-
Creating the array:
a = np.array([1.1, 2, 3])
creates a NumPy array. The array contains a mix offloat
(1.1) andint
(2 and 3).
-
NumPy Array Type Promotion:
- NumPy automatically promotes the data type of the array to a common type that can hold all the values. Since there is a float (
1.1
), NumPy will convert the entire array to thefloat64
data type to accommodate the decimal values.
- NumPy automatically promotes the data type of the array to a common type that can hold all the values. Since there is a float (
-
a.dtype
:- This returns the data type of the elements in the array. Since the array contains a float, the dtype will be
float64
.
- This returns the data type of the elements in the array. Since the array contains a float, the dtype will be
Conclusion:
The output will be float64
.
Answer:
(B) float64