liveBook · Manning

Inner product

As explained in Deep Learning with JAX

A linear algebra operation that multiplies corresponding elements of two arrays and sums the products.

A dot product combines two same-length vectors by multiplying corresponding elements and summing the results. In JAX, jnp.vdot handles the operation directly. section 6.1

A small JAX calculation

def dot(v1, v2): return jnp.vdot(v1, v2) dot(jnp.array([1., 1., 1.]), jnp.array([1., 2., -1.])) >>> Array(2., dtype=float32) The result is 2: 1×1 + 1×2 + 1×−1. section 6.1

A function written for one vector pair does not automatically accept a batch. Passing 32 images can produce a contracting-dimensions error because the batch dimension is mistaken for part of the dot product. section 2.5

Listing 6.1 A function for calculating a dot product between two vectors
def dot(v1, v2):
  return jnp.vdot(v1, v2)                              #1
  
dot(jnp.array([1., 1., 1.]), jnp.array([1., 2., -1]))  #2
  
>>> Array(2., dtype=float32)

Inspect the compact JAX implementation and its numerical result. section 6.1

How Deep Learning with JAX covers it

How deep it goes
Defines the operation, demonstrates jnp.vdot, and diagnoses a batch-shape failure without deriving contraction internals.
Examples
Uses two three-element vectors, random arrays of vectors, and a batch of 32 flattened 28×28 images.
What it assumes
Assumes familiarity with arrays and basic neural-network calculations while distinguishing vectors, matrices, tensors, and scalars.
What you can do after
Apply it via JAX's jnp.vdot, recognize incompatible batch shapes, and prepare single-item functions for vmap.
How it connects
Connects vectors, tensors, matrices, batching, neural networks, and vmap-based automatic vectorization.

Also explained in

Compare how 12 books explain inner product →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with JAX. The section links point to the parts of the book it draws on.