Chapter 5. Advanced Array Concepts

In this chapter, we will explain some more advanced aspects of arrays. First, we will cover the notion of an array view, followed by Boolean arrays and how to compare arrays. We briefly describe indexing and vectorization, explain sparse arrays, and some special topics such as broadcasting.

Array views and copies

In order to control precisely how memory is used, NumPy offers the concept of view of an array. Views are smaller arrays that share the same data as a larger array. This works just like a reference to one single object (refer to section Basic Types in Chapter 1, Getting Started).

Array views

The simplest example of a view is given by a slice of an array:

M = array([[1.,2.],[3.,4.]]) v = M[0,:] # first row ...

Get Scientific Computing with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.