From the course: NumPy Essential Training: 1 Foundations of NumPy

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Python lists vs. NumPy arrays

Python lists vs. NumPy arrays

- [Lecturer] Lists and arrays are both used to store data in Python, but why would you choose one over the other? You'll be surprised that such a decision can have a significant impact on performance and memory footprint. First, let's explore what these data structures have in common. Both, lists and arrays have similar syntax. Their elements are ordered, mutable and are able to store duplicate items. They also allow indexing, slicing and iterating. Let's see what the differences are. The first difference is that lists are built-in data structures, while arrays must be imported. To use the arrays in Python, you have to import them from the NumPy package, or from the Array module. Unlike arrays which can hold only data of the same data type, for example, only integers, or only strings, lists can hold elements of different types. For NumPy arrays, once we define the dimension of an array, we're limited, and cannot expand it anymore. While for lists, we are flexible, as it expands as we…

Contents