Getting started with NumPy
The NumPy library revolves around its multidimensional array object, numpy.ndarray
. NumPy arrays are collections of elements of the same data type; this fundamental restriction allows NumPy to pack the data in a way that allows for high-performance mathematical operations.
Creating arrays
Let's explore NumPy's functionalities by following these steps:
- 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 thea
array, we will find that itsdtype
isint64
, which stands for 64-bit integer:a.dtype ...