{ } Raw JSON

bundles / scipy 1.17.1 / scipy / linalg / _matfuncs / khatri_rao

function

scipy.linalg._matfuncs:khatri_rao

source: /scipy/linalg/_matfuncs.py :995

Signature

def   khatri_rao ( a b )

Summary

Khatri-Rao product of two matrices.

Extended Summary

A column-wise Kronecker product of two matrices

The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. Note that calls with zero-size batches are unsupported and will raise a ValueError.

Parameters

a : (n, k) array_like

Input array

b : (m, k) array_like

Input array

Returns

: c: (n*m, k) ndarray

Khatri-rao product of a and b.

Notes

The mathematical definition of the Khatri-Rao product is:

which is the Kronecker product of every column of A and B, e.g.

c = np.vstack([np.kron(a[:, k], b[:, k]) for k in range(b.shape[1])]).T

Examples

import numpy as np
from scipy import linalg
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([[3, 4, 5], [6, 7, 8], [2, 3, 9]])
linalg.khatri_rao(a, b)

Aliases

  • scipy.linalg.khatri_rao

Referenced by

This package