December 2026
Every post published in December 2026, newest first. Pick a day to jump straight to it.
- Posts
- 410
- Topics
- 77
- Reading time
- 40 h
- Active days
- 3
Posts 241–270 of 410 · December 2, 2026
Page 9 of 14
Wednesday, December 2, 2026
30 of 81 posts
How to Add Up the Values of a Tensor in PyTorch with sum()
Add up a PyTorch tensor's values with sum(): every value into one total, down each column with dim=0, or along each row with dim=1, and keep the shape with keepdim. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Multiply Matrices in PyTorch with torch.matmul
Multiply two matrices in PyTorch with torch.matmul or the @ operator, see how it differs from * (value by value), and fix the shape and data type errors it raises. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Transpose a Matrix in PyTorch with .T
Swap a PyTorch matrix's rows and columns with .T, see that the result shares its values with the original, and use .mT for a batch of matrices instead of the deprecated .T on three dimensions. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Turn a PyTorch Tensor into a Python List with tolist()
Convert a PyTorch tensor into a plain Python list of numbers with tolist(), nested for a table, straight from the GPU too, and see why list(tensor) gives a list of tensors instead. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Get a Python Number from a PyTorch Tensor with item()
Turn a one-value PyTorch tensor into a plain Python number with item(), from the CPU or the GPU, and fix the RuntimeError it raises on a tensor with more than one value. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
3 min readHow to Move a Tensor to the GPU in PyTorch
Copy a PyTorch tensor from the CPU to the GPU with .to(device), choosing Apple MPS, NVIDIA CUDA or the CPU automatically, and keep the result, because .to() returns a new tensor. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Move a Tensor Back to the CPU in PyTorch with .cpu()
Copy a PyTorch tensor from the GPU back to the CPU with .cpu(), the step NumPy needs before .numpy() works. Real output from PyTorch 2.15.0 on an Apple M1 Pro, including the TypeError .numpy() gives on a GPU tensor.
4 min readHow to Make a Key Optional in a Python TypedDict with NotRequired
Let a TypedDict dictionary leave out a key by marking it NotRequired, so a type checker accepts it with or without that key. Real output from Python 3.15.2 and mypy 2.4.1, plus why str | None doesn't make a key optional.
5 min readHow to Get the Same Random Numbers Every Run in PyTorch with torch.manual_seed
Make PyTorch's random numbers repeat on every run with torch.manual_seed, on the CPU and on the GPU, and see why the same seed gives different numbers on each. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
5 min readHow to Create a Range of Numbers in PyTorch with torch.arange
Make a PyTorch tensor of evenly spaced numbers with torch.arange: from 0, between two values, with a step, or with a decimal step, and see why the end value is never included. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
3 min readHow to Capitalize Each Word of a String in Python with title()
Start every word of a Python string with a capital letter with str.title(), which also makes the rest of each word lowercase. Real output from Python 3.15.2, plus why it capitalizes the letter after an apostrophe and how capitalize() differs.
4 min readHow to Create a Tensor of Zeros in PyTorch with torch.zeros
Make a PyTorch tensor filled with zeros in any shape with torch.zeros, as decimals by default or as whole numbers with dtype, and on the GPU with device. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Create a Tensor of Ones in PyTorch with torch.ones
Make a PyTorch tensor filled with ones in any shape with torch.ones, as decimals by default or as whole numbers with dtype, and fill a tensor with any other number using torch.full. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Create a Tensor of Random Numbers in PyTorch with torch.rand
Make a PyTorch tensor of random decimals between 0 and 1 in any shape with torch.rand, see that each run gives new numbers, and get random whole numbers with torch.randint. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
4 min readHow to Check Which Device a Tensor Is On in PyTorch
Read where a PyTorch tensor lives with .device and .device.type: the CPU, an Apple silicon GPU (mps:0) or an NVIDIA GPU (cuda:0). Real output from PyTorch 2.15.0 on an Apple M1 Pro, plus the device comparison that quietly returns False.
4 min readHow to Check the Data Type of a Tensor in PyTorch
Read a PyTorch tensor's data type with .dtype and see what PyTorch picks for whole numbers, decimals and True/False values: torch.int64, torch.float32 and torch.bool. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
3 min readHow to Create a Tensor in PyTorch with torch.tensor
Turn a Python list into a PyTorch tensor with torch.tensor: a list of numbers becomes a one-dimensional tensor and a list of lists a table. Real output from PyTorch 2.15.0 on an Apple M1 Pro, plus the errors that ragged rows and torch.Tensor cause.
4 min readHow to Get the Shape of a Tensor in PyTorch
Read a PyTorch tensor's shape with .shape or .size(), and the length of one dimension with .shape[0] or .size(1). Real output from PyTorch 2.15.0 on an Apple M1 Pro, plus the error .shape() with brackets causes.
4 min readFixed: No overload variant of "stream" of "Pregel" matches argument types
mypy rejected a working LangGraph graph with No overload variant of "stream" of "Pregel" matches argument types "dict[str, str]", "str". The input left out a key that the State TypedDict requires. Marking that key NotRequired, or giving the graph an input schema, fixed it.
9 min readFixed: LangGraph graph.stream() Prints Nothing and Raises No Error
A LangGraph graph streamed with stream_mode="update" printed nothing and exited with code 0. LangGraph 1.2.25 doesn't check the mode's name and only emits for names it knows, such as "updates". Spelling the mode right brought back one line per node.
6 min readHow to See What Each Node Returns in a LangGraph Graph in Python
Print what every node of a LangGraph graph returns, one node at a time, with graph.stream() and stream_mode="updates", instead of only the final state that invoke() gives you. Real output from LangGraph 1.2.25, plus the "values" mode and the version="v2" format.
7 min readHow to Check Which Version of PyTorch Is Installed
Print PyTorch's version with torch.__version__ and the CUDA version it was built with using torch.version.cuda, or read the version without importing PyTorch through uv pip show torch. Real output from PyTorch 2.15.0 on an Apple M1 Pro.
5 min readFixed: Distribution torch==2.15.0+cu132 can't be installed because it doesn't have a source distribution or wheel for the current platform
uv add torch failed on a Mac with Distribution torch==2.15.0+cu132 can't be installed because it doesn't have a source distribution or wheel for the current platform, after pyproject.toml sent torch to PyTorch's CUDA index. PyTorch has no CUDA builds for macOS; a sys_platform marker limits the index to Windows.
6 min readHow to Install PyTorch with uv
Install PyTorch into a Python project with uv add torch, see what you get on macOS, Windows and Linux, check the version, and clear the NumPy warning a bare install prints. Real output from PyTorch 2.15.0 on Python 3.15.2 and an Apple M1 Pro.
7 min readHow to Install LangGraph in Python with uv
Install LangGraph in a uv project on Python 3.14, check the installed version, and run a one-node graph to prove it works, with no API key. Real output from LangGraph 1.2.25, plus why Python 3.15 has to build one of its packages from source.
9 min readFixed: You tried to install "pytorch". The package named for PyTorch is "torch"
uv add pytorch failed with a long build error ending in Exception: You tried to install "pytorch". The package named for PyTorch is "torch". The package on PyPI is called torch; uv add torch installs PyTorch 2.15.0. Real output from uv 0.13.10 on Python 3.15.2.
6 min readHow to Install PyTorch with CUDA Using uv
Make uv install PyTorch's CUDA 13.2 build on Windows, where PyPI's torch has no CUDA, while macOS and Linux keep PyPI's builds: one [[tool.uv.index]] and a sys_platform marker in pyproject.toml. Real uv add and uv tree output for all three systems from PyTorch 2.15.0.
7 min readHow to Call One Method After Another in Python with Method Chaining
Chain Python method calls, such as name.strip().title().split(), where each call works on the result of the one before it, and see why a method that returns None, like list.sort(), breaks the chain. Real output from Python 3.15.2.
4 min readHow to Write a Decimal Number in Python with float
Write numbers with a decimal point, such as 19.99 or 2.0, which Python stores as float, see how type() tells them from whole numbers, and why 0.1 + 0.2 prints 0.30000000000000004. Real output from Python 3.15.2.
4 min readHow to Create a List of Lists in Python
Store rows and columns, such as seats in a cinema, as a Python list of lists: write it with nested square brackets, read one row with grid[row] and one item with grid[row][col], and count rows and columns with len(). Real output from Python 3.15.2.
4 min read