liveBook · Manning

Matrix-matrix multiplication

As explained in Build AI Drug Discovery Pipelines

Matrix multiplication is the arithmetic operation that combines matrices to produce a matrix of weighted linear transformations.

Matrix-matrix multiplication combines two tensors by multiplying rows and columns. In PyTorch, use torch.matmul() or the @ operator; both produce the same result and avoid slow explicit loops. section 8.1.2

Check tensor shapes before multiplying:

  • The inner dimensions must match, so incompatible shapes such as (3, 2) @ (3, 2) fail. section 8.1.2
  • Transpose a tensor with .T when dimensions need rearranging for multiplication. section 8.1.2
  • Use torch.matmul() or @ rather than computing products with for loops. section 8.1.2

Multiplying a tensor by its transpose

tensor_2d.matmul(tensor_2d.T) and tensor_2d @ tensor_2d.T both produce tensor([[14, 32], [32, 77]]) for tensor_2d = [[1, 2, 3], [4, 5, 6]]. section 8.1.2

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains the operators, shape constraint, transpose support, and worked output, but not the underlying arithmetic algorithm.
Examples
Demonstrates multiplying a two-dimensional tensor by its transpose with matmul() and @.
What it assumes
Assumes familiarity with tensors and their shapes while introducing transpose-based dimension alignment.
What you can do after
Apply it via PyTorch using torch.matmul() or @ while checking compatible tensor dimensions.
How it connects
Connects matrix multiplication with tensors, tensor shapes, transposition, reshaping, and PyTorch.

Also explained in

Compare how 13 books explain matrix-matrix multiplication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.