Computational Foundations Lab developed as part of the Python for Data Science curriculum in the MSc Data Science & AI for Business (École Polytechnique / HEC Paris).
Writing scalable, production-grade Data Science code requires understanding what happens beneath the Python interpreter. This project explores the foundational computational principles of modern scientific computing:
- Floating-Point Precision & IEEE 754 Standard: Unpacking precision limits, binary fraction representation, catastrophic cancellation, and robust approximate equality testing via
np.allclose(). - CPython Memory Model & Mutability: Inspecting memory allocation, object references (
id()), integer interning, in-place mutations vs. new object rebinding, and shallow vs. deep copy semantics. - Vectorized Computation vs. Native Loops: Benchmarking the architectural speedups of NumPy contiguous C-arrays (SIMD operations, cache locality, and vectorization) against standard Python
forloops. - Efficient Python Idioms: Advanced strided slicing, dictionary hash maps for frequency counting, and memory-efficient list/generator comprehensions.
Computers store real numbers in binary base-2 floating-point representation. Fractions such as
result = 0.1 + 100 - 100
print(result == 0.1) # False! Due to precision rounding
print(np.allclose(result, 0.1)) # True: uses absolute and relative tolerance-
Core Lesson: Never check exact equality (
==) on floating-point results in data engineering or financial pipelines; always evaluate within numerical tolerances:$$|a - b| \le (\text{atol} + \text{rtol} \cdot |b|)$$
Exploring how Python handles pointers and object identity in memory:
a = 1000
b = 1000
print(a is b) # False (separate memory allocations)
c = a
a += 1 # Integers are immutable: rebinds 'a' to a new integer object
print(c) # Remains 1000! 'c' still points to the initial memory address- Data Structure Mechanics:
- Immutable types (
int,float,tuple,str): Cannot be modified in-place; operations create new objects. - Mutable types (
list,dict,np.ndarray): In-place modification alters all shared references, a frequent source of silent bugs in data processing pipelines.
- Immutable types (
Comparing array squaring over
# Native Python loop
squares = [i**2 for i in range(1, 12)]
# NumPy vectorized SIMD computation
np_squares = np.arange(1, 12)**2- Architectural Differences:
- Native Python: Interpreted dynamic type checking on each iteration, object boxing/unboxing overhead, and fragmented pointer-based memory layouts causing CPU cache misses.
- NumPy: Contiguous memory buffers, static C data types, SIMD (Single Instruction, Multiple Data) parallel CPU vectorization, yielding 50x–100x speedups on numerical operations.
├── python_data_science_foundations.ipynb # Complete annotated Jupyter notebook
├── report.html # Standalone interactive HTML report
└── README.md
# Clone the repository
git clone https://github.com/victorpiana/python-data-science-foundations.git
cd python-data-science-foundations
# Environment setup
python -m venv venv
source venv/bin/activate
pip install numpy pandas matplotlib scikit-learnOpen notebook:
jupyter lab python_data_science_foundations.ipynbOr open report.html directly in your web browser.
Victor Piana
- Master of Science in Data Science & AI for Business — École Polytechnique & HEC Paris
- LinkedIn: linkedin.com/in/victor-piana-107230238
- GitHub: @victorpiana