Tsallaka zuwa abun ciki
Justice Tech School

dtype and Type Conversion

Every array has one dtype such as int64 or float64. astype converts to another.

Example
a = np.array([1, 2, 3])
b = a.astype(float)
print(a.dtype, b.dtype, np.array([1, 2.5]).dtype)
print(np.array(["1", "2"]).astype(int))

Result

int64 float64 float64
[1 2]

Exercise

Convert type.

a.(float)

Quiz Test

Can an array hold mixed types?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.