February 2019
Intermediate to advanced
672 pages
16h 50m
English
You can create NumPy arrays using the numpy.array function. It takes a list-like object (or another array) as input and, optionally, a string expressing its data type. You can interactively test array creation using an IPython shell, as follows:
import numpy as np a = np.array([0, 1, 2])
Every NumPy array has an associated data type that can be accessed using the dtype attribute. If we inspect the a array, we find that its dtype is int64, which stands for 64-bit integer:
a.dtype # Result: # dtype('int64')
We may decide to convert those integer numbers to float type. To do this, we can either pass the dtype argument at array initialization or cast the array to another data type using the astype method. The two ways ...