NumPy-datatypes

Introductie tot NumPy

Izzy Weber

Core Curriculum Manager, DataCamp

NumPy vs. Python-datatypes

 

Voorbeelden Python-datatypes:

  • int
  • float

 

Voorbeelden NumPy-datatypes:

  • np.int64
  • np.int32
  • np.float64
  • np.float32
Introductie tot NumPy

Bits en bytes

Het getal 10436 in binair is:

Een afbeelding van het getal 10436 in binair  

np.int32 kan 4.294.967.296 integers opslaan:

Een diagram van de opslagcapaciteit van np.int32

Introductie tot NumPy

Bits en bytes

Het getal 10436 in binair is:

Een afbeelding van het getal 10436 in binair  

np.int32 kan 4.294.967.296 integers opslaan:

Een diagram van de opslagcapaciteit van np.int32

Introductie tot NumPy

Het attribuut .dtype

np.array([1.32, 5.78, 175.55]).dtype
dtype('float64')
Introductie tot NumPy

Standaarddatatypes

int_array = np.array([[1, 2, 3], [4, 5, 6]])
int_array.dtype
dtype('int64')
Introductie tot NumPy

Stringdata

np.array(["Introduction", "to", "NumPy"]).dtype
dtype('<U12')
Introductie tot NumPy

dtype als argument

float32_array = np.array([1.32, 5.78, 175.55], dtype=np.float32)
float32_array.dtype
dtype('float32')
Introductie tot NumPy

Typeconversie

boolean_array = np.array([[True, False], [False, False]], dtype=np.bool_)
boolean_array.astype(np.int32)
array([[1, 0],
       [0, 0]], dtype=int32)
Introductie tot NumPy

Typecoercion

np.array([True, "Boop", 42, 42.42])
array(['True', 'Boop', '42', '42.42'], dtype='<U5')
Introductie tot NumPy

Hiƫrarchie van typecoercion

Een float toevoegen aan een integer-array zet alle integers om naar floats:

np.array([0, 42, 42.42]).dtype
dtype('float64')

 

Een integer toevoegen aan een boolean-array zet alle booleans om naar integers:

np.array([True, False, 42]).dtype
dtype('int64')
Introductie tot NumPy

Laten we oefenen!

Introductie tot NumPy

Preparing Video For Download...