pagemtimes

Matrix multiplication page by page for N-D arrays.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = pagemtimes(A, B)

Multiplies each page A(:,:,k) by the matching page B(:,:,k).

C = pagemtimes(A, transpA, B, transpB)

Transposes pages first. The flags are 'none', 'transpose' or 'ctranspose'.

Description

It is a batched A*B: for 3-D input it equals a loop C(:,:,k) = A(:,:,k) * B(:,:,k), but in one call. A page dimension of size 1 is reused for all pages, so a single matrix can multiply a whole stack.

This is useful for rotating many points with the same matrix, or computing many small products at once.

Input arguments

A, B
Numeric arrays whose pages are conformable for matrix multiplication. Dimensions beyond the second must match or be 1.
transpA, transpB
Operation applied to each page before multiplying.

Output arguments

C
Array with size(C,1) = size(A,1) and size(C,2) = size(B,2), holding the products page by page.

Example

A = cat(3, [1 2; 3 4], [0 1; 1 0]);
B = cat(3, [1 0; 0 1], [2 3; 4 5]);
C = pagemtimes(A, B);
C(:, :, 1)
C(:, :, 2)
size(pagemtimes(ones(2, 3, 4), ones(3, 5, 4)))
Output
ans = 2×2

     1     2
     3     4
ans = 2×2

     4     5
     2     3
ans = 1×3

     2     5     4

See also

pagetranspose pagemldivide mtimes tensorprod *