Creating and loading arrays
In this section, we will see how we can create and load arrays either from scratch or from existing data. This is the first step when analyzing data with Python.
There are several ways of creating an array. We will review them in this section.
From scratch, element by element
First, we can create an array by manually specifying its coefficients. This is the most direct way of creating an array, but it is not used very often in practice. The NumPy function
array takes a list of elements and returns a corresponding NumPy array, as shown in the following example (the
pylab mode of IPython needs to be activated):
In : x = array([1, 2, 3]) In : x.shape Out: (3,) In : x.dtype Out: dtype('int32') ...