internalsGet Pro

Module 02 · Lesson 7 of 8Pro

PyTorch tensors: shapes, axes and operations

Level
Beginner
Topic
Python for machine learning
Reading time
14 min

When you finish this page you can

  1. Read a tensor’s shape, dtype and device, and say what each axis of a batch of photos means.
  2. Choose between reshape and permute, and spot the reshape that scrambles data without an error.
  3. Apply reductions, broadcasting and matrix multiplication to tensors and predict the result shape.
  4. Move tensors between NumPy, the CPU and a GPU without dtype or device errors.

Builds on 2 lessons

Start with lesson 113 min
  1. The ML toolkit: a map of libraries and platforms13 min
  2. NumPy: arrays and vectorized maths14 min

The right shape, the wrong pixels

is our example online store. Sellers upload product photos, and Joseph’s growth team wants each new product sorted into one of 20 categories, so it shows up in the right recommendations. Farah, an ML engineer, is building that photo classifier on a notebook-sized sample of about 100,000 labelled photos.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan