📖 Scenario: Imagine you want to work with numbers in your computer, like adding many numbers or finding averages. Doing this with just normal lists can be slow and tricky. NumPy is a tool that helps you work with numbers easily and fast.
🎯 Goal: You will create a simple list of numbers, then use NumPy to turn it into a special array. You will also see how to print this array to understand what NumPy does.
📋 What You'll Learn
Create a list of numbers
Import the NumPy library
Convert the list to a NumPy array
Print the NumPy array
💡 Why This Matters
🌍 Real World
NumPy is used in science, engineering, and data analysis to handle large sets of numbers quickly and easily.
💼 Career
Knowing NumPy is important for jobs in data science, machine learning, and any role that involves working with numbers and data.
Progress0 / 4 steps
1
Create a list of numbers
Create a list called numbers with these exact values: 10, 20, 30, 40, 50.
NumPy
Hint
Use square brackets [] to create a list and separate numbers with commas.
2
Import the NumPy library
Import the NumPy library using the alias np.
NumPy
Hint
Use the import keyword followed by numpy as np.
3
Convert the list to a NumPy array
Create a variable called array_numbers and set it to the NumPy array version of the numbers list using np.array().
NumPy
Hint
Use np.array() and pass the list numbers inside the parentheses.
4
Print the NumPy array
Print the variable array_numbers to see the NumPy array output.
NumPy
Hint
Use the print() function to display the array.
Practice
(1/5)
1. What is NumPy mainly used for in data science?
easy
A. Handling and performing math on large sets of numbers efficiently
B. Creating web pages and styling them
C. Managing databases and SQL queries
D. Writing scripts to automate emails
Solution
Step 1: Understand NumPy's purpose
NumPy is designed to handle large arrays of numbers and perform math operations quickly.
Step 2: Compare options with NumPy's role
Creating web pages and styling them, managing databases and SQL queries, and writing scripts to automate emails are not NumPy's focus.
Final Answer:
Handling and performing math on large sets of numbers efficiently -> Option A
Quick Check:
NumPy = Efficient number handling [OK]
Hint: NumPy is about numbers and math, not web or databases [OK]
Common Mistakes:
Confusing NumPy with web or database tools
Thinking NumPy is for text processing
Assuming NumPy handles emails or automation
2. Which of the following is the correct way to import NumPy in Python?
easy
A. import numpy as numpy
B. import numpy as np
C. import np as numpy
D. import numpy from np
Solution
Step 1: Recall standard NumPy import syntax
The common and correct way is 'import numpy as np' to use 'np' as shorthand.
Step 2: Check other options for syntax errors
'import numpy as numpy' repeats 'numpy' without proper aliasing; 'import np as numpy' and 'import numpy from np' have wrong order or keywords.
Final Answer:
import numpy as np -> Option B
Quick Check:
Standard import = import numpy as np [OK]
Hint: Remember: 'import numpy as np' is the standard [OK]