/Curriculum/Core NumPyMath Operations

12. NumPy Array ArithmeticBeginner

Element-wise addition, subtraction, multiplication, division, power, and floor division.

12 mins

Concept Overview

All standard arithmetic operators (`+`, `-`, `*`, `/`, `//`, `%`, `**`) operate element-wise in NumPy at compiled C-speed using SIMD vector registers.

Hardware Mental Model

Unlike Python lists where `list * 2` duplicates the list, in NumPy `arr * 2` multiplies every single number inside by 2 simultaneously.

Key Concepts (1)Click snippet to load in editor

Operations between arrays of the same shape apply to matching index positions in parallel.

res = a + b

⚠ Common Mistakes & Pitfalls

Avoid these frequent beginner syntax and logic traps
❌ Incorrect:a = [1, 2, 3]; b = [4, 5, 6]; c = a + b # Python list concatenation [1,2,3,4,5,6]
✓ Correct:a = np.array([1, 2, 3]); b = np.array([4, 5, 6]); c = a + b # NumPy [5, 7, 9]

Standard Python `+` concatenates lists; NumPy `+` computes numerical element-wise addition.

Pro Tip: Always ensure your lists are converted to `np.array` before performing arithmetic.

📌 Quick Revision

Core takeaway points from this topic
Operators apply element-wise: `+`, `-`, `*`, `/`, `//`, `%`, `**`.
Scalar arithmetic applies the scalar to every element in the array.
Array-to-array arithmetic pairs matching elements by index.
Editor: 12. NumPy Array Arithmetic
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state

🎯 Try It Yourself: Practice Challenge

Hands-on Mode

Solve the objective below using NumPy vectorized syntax

Objective:Multiply Array by Scalar

Create `arr = np.array([2, 4, 6, 8])`, multiply by 5 using `arr * 5`, and print.

Expected Output Target:[10 20 30 40]
Practice Workspace
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state