Skip to content

Kronecker product #652

Closed
Closed
@emmatyping

Description

@emmatyping

Myself (and another user on the rust discord) have run into the need for the kronecker product of two matrices.

I currently have code like:

fn kron(a: &Array2<f64>, b: &Array2<f64>) -> Array2<f64> {
    let dima = a.shape()[0];
    let dimb = b.shape()[0];
    let dimout = dima * dimb;
    let mut out = Array2::zeros((dimout, dimout));
    for (mut chunk, elem) in out.exact_chunks_mut((dimb, dimb)).into_iter().zip(a.iter()) {
        chunk.assign(&(*elem * b));
    }
    out
}

(note: in my code I only work on unitary matrices, so this is not general in a few ways)

It would be nice to have a general implementation of this in ndarray (numpy as np.kron).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions