Creating Your First NumPy Array
Introduction
Welcome to From Lists to Arrays. In this course, we move from familiar Python lists to NumPy arrays, the basic building block for working with numerical data in Python. In this first lesson we only build arrays and look at them; using them for calculations comes later in the path. We will start with a list of daily step counts, convert it into a NumPy array in one line, and inspect what changes: how the values print, the array’s type, and its length.
What Is NumPy, and Why Does It Matter?
NumPy, short for Numerical Python, is a library for working with numbers in bulk. Its central tool is the array: a container that holds many values of the same kind. Real data work often involves thousands or millions of numbers, such as sensor readings, prices, or measurements. NumPy stores them compactly and processes them with fast, optimized code, so the same work runs much faster and uses less memory than it would with plain Python lists. NumPy is also the foundation of the wider data tools in Python: libraries such as pandas and Matplotlib build on NumPy arrays. That makes NumPy the natural first step into data analysis, scientific computing, and machine learning.
Importing NumPy
To use NumPy, we first import it. The alias np is the standard shorthand you will see in NumPy tutorials and codebases, so using it makes our examples easier to recognize. NumPy is already available in the CodeSignal IDE, which means we can focus on using it.
This statement makes NumPy’s tools available through np. We will use one of those tools, np.array, to create an array from our list.
Our Starting Point: A Python List
We will use five daily step counts as our example. For now, they are stored in a regular Python list. Printing the list gives us a clear before picture: its values appear inside square brackets, separated by commas.
The output shows the list exactly as Python displays it:
Next, we will keep this list and create a NumPy array from its values.
