0
0
NumPydata~15 mins

Converting to and from Python lists in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Converting to and from Python lists
📖 Scenario: Imagine you work in a small bakery. You have a list of daily sales numbers. You want to use NumPy to do some quick calculations, but first, you need to convert your Python list into a NumPy array. Later, you want to convert the NumPy array back to a Python list to share with your team.
🎯 Goal: Learn how to convert a Python list to a NumPy array and then convert it back to a Python list.
📋 What You'll Learn
Create a Python list with exact sales numbers
Import the NumPy library
Convert the Python list to a NumPy array
Convert the NumPy array back to a Python list
Print the final Python list
💡 Why This Matters
🌍 Real World
Data scientists often receive data in Python lists but use NumPy arrays for fast calculations. Knowing how to switch between these formats helps in data cleaning and sharing results.
💼 Career
This skill is essential for data analysts and scientists who work with numerical data and need to prepare it for analysis or visualization.
Progress0 / 4 steps
1
Create the sales list
Create a Python list called sales with these exact numbers: 15, 22, 13, 27, 19.
NumPy
Need a hint?

Use square brackets [] to create a list and separate numbers with commas.

2
Import NumPy and convert list to array
Import the NumPy library as np. Then create a NumPy array called sales_array by converting the sales list using np.array().
NumPy
Need a hint?

Use import numpy as np to import NumPy. Use np.array() to convert the list.

3
Convert NumPy array back to Python list
Create a new variable called sales_list_again by converting the sales_array NumPy array back to a Python list using the tolist() method.
NumPy
Need a hint?

Use the tolist() method on the NumPy array to get a Python list.

4
Print the final Python list
Print the variable sales_list_again to display the Python list converted back from the NumPy array.
NumPy
Need a hint?

Use print() to show the list on the screen.