Skip main navigation

Differences between Python list and NumPy array

Python lists are very flexible, but memory access performance is not optimal. In this video Jussi Enkovaara shows what NumPy arrays more efficient.
Python lists are very flexible as one can store different types of Python objects within the same list. Also, one can add and remove items at any point in the list. However, this flexibility will come with the price as the list items will be scattered all over the computer memory and accessing to memory is slower than if the data is accessed in contiguous manner. Due to inherent dynamic nature of the Python list, the data is scattered in the computer memory even when all the items are just numbers and one would construct the whole list at once.
NumPy array on the other hand overcomes these shortcomings in the memory performance. As both type and number of array elements is fixed at the time of creating the array NumPy knows how much memory is needed for the array and allocates large enough contiguous block. Thus, the array data can be laid out contiguously into computer memory and accessing successive array elements is much faster than in case of Python list. Contiguous memory layout allows also easier passing of NumPy arrays into high-performance libraries.

Python lists are very flexible, but not always optimal for numerical computations.

In this video we discuss the main differences between Python list and NumPy array which is the most important Python data structure for storing numeric data.

This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education