TensorTonic guides

How Much Python Do You Need Before Learning Machine Learning?

How much Python you need before machine learning: a readiness checklist, the NumPy skills that matter more than syntax, a worked example and a self-test.

By TensorTonic's founderLast updated 6 min read

How much Python do you need before you start machine learning?

Less than most people think. Before starting ML, you need to write functions, use lists and dictionaries, loop and branch, read error messages, and work with NumPy arrays, including shapes, indexing, broadcasting and vectorized operations. Basic pandas helps. Advanced Python such as decorators, async code or metaclasses can wait until you build production systems.

The NumPy study plan covers the array skills in the table below as small problems with tests.

Python skills to learn before machine learning
SkillNeeded before ML?Why it matters in ML
Variables, types and functionsYesEvery preprocessing step, loss and metric is a function
Lists, dictionaries, loops, comprehensionsYesData preparation, counting, batching
Reading tracebacks and debuggingYesShape errors and type errors are daily events
NumPy arrays, with shapes, indexing and broadcastingYes, and it matters mostML math is array math
Classes, at a basic levelYes, before deep learningPyTorch models are classes that inherit from nn.Module
pandas basicsHelpfulLoading and cleaning tabular data
Plotting with MatplotlibHelpfulLoss curves and data checks
Virtual environments and pipHelpfulInstalling and isolating libraries
Decorators, generators, async, type hintsLaterProduction and library code
Packaging and testing frameworksLaterShipping code other people use

Which Python skills matter most for ML?

Four skills carry most of the weight early on.

  • Functions with clear inputs and outputs matter because ML code is a pipeline of transformations that load, clean, split, train and evaluate. Writing each step as a function you can test on its own saves hours of debugging.
  • Core data structures come up everywhere, with lists for sequences, dictionaries for lookups and counts, and tuples for fixed records. Tokenizers, vocabularies and config files are all built from them.
  • Reading errors is one of the most useful debugging skills you can have. A traceback tells you the file, the line and usually the cause, and it reads best from the bottom up.
  • Basic classes are enough at the start. You do not need object-oriented design patterns, but in PyTorch you define a model as a class with an __init__ and a forward method, so you need to be comfortable with both.

Why does NumPy matter more than advanced Python?

Almost every ML operation is an operation on arrays, and NumPy is how Python does arrays. Good ML code replaces Python loops with vectorized operations that run on whole arrays at once. Here is mean squared error written both ways, followed by a bug that catches many beginners.

import numpy as np

y_true = np.array([3.0, 5.0, 2.0])
y_pred = np.array([2.5, 5.0, 3.0])

total = 0.0
for t, p in zip(y_true, y_pred):
    total += (t - p) ** 2
mse_loop = total / len(y_true)

mse_vec = np.mean((y_true - y_pred) ** 2)

wrong = np.mean((y_true.reshape(-1, 1) - y_pred) ** 2)

The loop version and the vectorized version both give 0.4167, and the vectorized one is how ML code is written. The last line runs without any error and returns 2.75, which is wrong, because a column of shape (3, 1) minus an array of shape (3,) broadcasts into a 3 by 3 grid. Shape bugs like this are common in ML code, so checking .shape before and after every operation is a habit worth building early.

Learn the NumPy skills in this order, starting with creating arrays, then shape and reshape, indexing and slicing, boolean masks, broadcasting, aggregations along an axis (axis=0 versus axis=1), and finally matrix multiplication with the @ operator.

What Python can wait until later?

You can start ML without any of these and pick them up when a project needs them.

  • Decorators and generators matter when you write libraries or data loaders for large datasets.
  • Async code matters when you serve models behind an API.
  • Type hints and packaging matter when other people use your code.
  • Advanced object-oriented design matters in large codebases.

If you later move into GPU work, you will also need some C or C++. Our guide on how to learn CUDA covers that path.

How do you know you are ready to start?

If you can do all five of these tasks without looking anything up, start ML now. If two or more are hard, spend a week or two on Python first.

  1. Write a function that takes a sentence and returns a dictionary counting each word.
  2. Given a NumPy array of exam scores, return only the scores above the mean, without a loop.
  3. Given a 2D array of shape (100, 5), compute the mean of each column, then subtract it from every row.
  4. Load a CSV with pandas and compute the average of one column grouped by another.
  5. Read a traceback for a shape mismatch error and say which line caused it and why.

Where should you learn the Python you are missing?

Resources for learning Python for ML
ResourceBest forCost
The official Python tutorialCore language, in orderFree
CS50's Introduction to Programming with Python (Harvard)Learning Python from zero with exercisesFree
NumPy, the absolute basics for beginnersArrays, shapes and broadcastingFree
10 minutes to pandasA fast tour of pandasFree
Python Data Science Handbook (Jake VanderPlas)NumPy, pandas, Matplotlib and scikit-learn in depthFree online

For structured practice with automatic feedback, the NumPy, pandas and PyTorch study plans turn these skills into problems with tests. The machine learning glossary is useful once the terms start piling up.

Practice this

Then browse the problem library.

Can you learn Python and machine learning at the same time?

Yes, if you already program in another language. If Python is your first language, learn the basics first, because debugging a model and the language at once makes both harder.

Is Python the only language used for machine learning?

It is the main one for building and training models. Production systems also use C++, Rust, Go and Java, and GPU kernels are written in CUDA C++ or Triton. For learning ML, Python is the right place to start.

Do you need to be a software engineer to start ML?

No. You need enough Python to write and debug small programs. Software engineering skills such as testing, version control and clean structure become important when you build real projects, and they are a big part of what separates ML engineers from people who only train models. See the self-taught ML engineer path for how those skills fit in.

Related guides

Keep reading