Tsallaka zuwa abun ciki
Justice Tech School

Data Types

Every array has one dtype such as int64, float64, bool or U5 for strings. Choose it with dtype= or convert with astype.

Example
import numpy as np
a = np.array([1, 2, 3], dtype=np.float32)
print(a, a.dtype)
b = a.astype(int)
print(b.dtype)
print(np.array([1, 2.5]).dtype, np.array([True, False]).dtype)

Result

[1. 2. 3.] float32
int64
float64 bool

Exercise

Convert the type.

a.(int)

Quiz Test

What dtype results from mixing 1 and 2.5?

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