Working with Fast Numerical Arrays for Analytics and Machine Learning¶
Notebook Guide¶
NumPy gives Python efficient array operations that power much of the data-science ecosystem.
Learning objectives¶
create and inspect arrays
perform vectorized arithmetic
summarize data with aggregate operations
understand why array thinking matters for ML workflows
import numpy as np
revenue = np.array([1200, 1350, 1280, 1425])
costs = np.array([700, 760, 710, 790])
profit = revenue - costs
print("Revenue:", revenue)
print("Costs:", costs)
print("Profit:", profit)
print("Average profit:", profit.mean())Revenue: [1200 1350 1280 1425]
Costs: [700 760 710 790]
Profit: [500 590 570 635]
Average profit: 573.75
Core Explanation¶
NumPy arrays allow element-wise arithmetic, fast aggregation, and predictable numerical behavior. That is why libraries such as pandas, scikit-learn, and many deep-learning tools build on the same array-oriented mindset.
Exercises¶
Create an array of monthly sales for six months.
Compute total sales and average sales.
Subtract an expense array from the sales array to estimate monthly profit.
8. Interactive Code¶
Expected output
[400 450 410]Expected output
420.0
4509. Guided Practice¶
Why is NumPy useful for numeric data work?¶
It replaces Python syntax completelyNumPy extends Python; it does not replace it.
It supports efficient array-based computationCorrect. Arrays and vectorized operations are key strengths.
It only works for text cleaningNumPy is mainly used for numeric computation.
It stores data only as dictionariesIts core structure is the array.
What is the average profit in the example?¶
400.0That is one value, not the mean.
420.0Correct. The mean of 400, 450, and 410 is 420.
430.0That is not the computed average.
450.0That is the maximum, not the mean.