Chapter 4. Numerical Computing with NumPy
Computers are useless. They can only give answers.
Pablo Picasso
Although the Python interpreter itself already brings a rich variety of data structures with it, NumPy and other libraries add to these in a valuable fashion. This chapter focuses on NumPy, which provides a multidimensional array object to store homogeneous or heterogeneous
data arrays and supports vectorization of code.
The chapter covers the following data structures:
| Object type | Meaning | Used for |
|---|---|---|
|
n-dimensional array object |
Large arrays of numerical data |
|
2-dimensional array object |
Tabular data organized in columns |
This chapter is organized as follows:
- “Arrays of Data”
-
This section is about the handling of arrays of data with pure Python code.
- “Regular NumPy Arrays”
-
This is the core section about the regular
NumPyndarrayclass, the workhorse in almost all data-intensive Python use cases involving numerical data. - “Structured NumPy Arrays”
-
This brief section introduces structured (or record)
ndarrayobjects for the handling of tabular data with columns. - “Vectorization of Code”
-
In this section, vectorization of code is discussed along with its benefits; the section also discusses the importance of memory layout in certain scenarios.
Arrays of Data
The previous chapter showed that Python provides some quite useful and flexible general data structures. In particular, list objects can be considered a real workhorse with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access