Articles → NUMPY → Dtype Attribute Of An Array In Numpy
Dtype Attribute Of An Array In Numpy
Purpose
Example
import numpy as np
# Creating an array of integers
arr_int = np.array([1, 2, 3, 4])
print(arr_int.dtype) # Output: int64 (or int32 depending on the platform)
# Creating an array of floats
arr_float = np.array([1.0, 2.0, 3.0, 4.0])
print(arr_float.dtype) # Output: float64
# Creating an array of complex numbers
arr_complex = np.array([1+2j, 3+4j])
print(arr_complex.dtype) # Output: complex128
# Creating an array of strings
arr_str = np.array(['a', 'b', 'c'])
print(arr_str.dtype) # Output: <U1 (Unicode string of length 1)
# Creating an array with a specified dtype
arr_specified = np.array([1, 2, 3, 4], dtype=np.float32)
print(arr_specified.dtype) # Output: float32
Output
Posted By - | Karan Gupta |
|
Posted On - | Friday, June 14, 2024 |