Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.dot

Computes dot products for scalar, vector, matrix, and higher-dimensional array combinations. Its exact operation depends on operand dimensionality, and an optional output array can receive the result.

How it works

numpy.dot combines arrays according to their dimensions: it computes an unconjugated inner product for two 1-D inputs, matrix multiplication for two 2-D inputs, scalar multiplication when either input is 0-D, and generalized sum-products for higher-dimensional combinations. The optional out array receives the result and is returned.

Syntax

numpy.dot(a, b, out=None)

Parameters

NameTypeDescription
aarray_likeFirst array operand.
barray_likeSecond array operand.
outndarray, optionalAn optional output array in which to place the result. It must have the correct shape, dtype, and be C-contiguous.

Returns

Scalar or ndarray; if out is supplied, that output array is returned.

Key points

  • numpy.dot computes a dot product between two array-like operands.
  • Two 1-D inputs produce an unconjugated vector inner product.
  • An N-D operand with a 1-D operand reduces the N-D operand's final axis.
  • The result is scalar only for scalar-scalar or 1-D/1-D cases; other cases return an array.
  • When supplied, out is both the destination for the result and the returned object.

Common mistakes

  • For two-dimensional matrix multiplication, prefer matmul or the @ operator.
  • Complex inputs are not conjugated for the one-dimensional inner product; use a conjugating operation when that is required.

Example: Vector inner product

import numpy as np

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(np.dot(a, b))  # 32

Computes the inner product of two one-dimensional arrays.

When to use it

Vector inner products

Compute a vector's similarity or weighted sum from matching one-dimensional numeric arrays.

Two-dimensional products

Apply a matrix multiplication operation when using the legacy dot API or dimension-specific behavior is required.

Higher-dimensional reductions

Reduce the final axis of a tensor against a vector using a sum-product.

Interview questions

QWhat does numpy.dot compute for 1-D and 2-D inputs?

For two 1-D arrays, numpy.dot returns their inner product without complex conjugation. For two 2-D arrays, it performs matrix multiplication.

Follow-up: How does it behave for an N-D array and a 1-D array? It sums products over the N-D array's last axis and the 1-D array.

QHow does dimensionality affect the return type?

If either operand is 0-D, the operation is equivalent to multiplication. For two scalars or two 1-D arrays, the result is a scalar; otherwise it is an array.

Follow-up: What should replace dot for scalar multiplication? Use numpy.multiply or the * operator.

QWhat is the purpose of the out parameter?

The signature is numpy.dot(a, b, out=None). a and b are the operands, while optional out specifies an output array that receives the result and is returned.

Follow-up: When should out be used? Use it when a suitably shaped output array is available and explicit output placement is useful.

  • numpy.matmul
  • numpy.multiply
  • numpy.inner
  • numpy.outer
  • numpy.vdot

Source: numpy.dot. Checked 2026-10-15.