[Python] Compute Eigenvalues for matrix when each element is a disjoint array

Discussão em 'Python' iniciado por Stack, Agosto 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have some 2x2 covariance matrix represented as 3 disjoint arrays, meaning 3 Nx1 arrays. The N is this case represents time so the covariance of some measurements overtime. I would like to be able to compute the eigenvalues at each time step without copying the individual arrays in a square matrix.

    I could have a 3x3 or 6x6 matrix (represented as individual columns for the upper triangle) with millions of time steps. Copying can be slow and prohibitively slow.

    Is there anyway to do this in numpy natively? I tried searching for how to make a view from multiple disjoint arrays but it doesn't appear that anything exists.

    A short snippet of example data with what I am trying to do.

    import numpy as np

    A = np.random.random([2,2])
    cov = np.dot(A, A.T)
    cov[1,0] = 0

    np.linalg.eigvalsh(cov, "U")
    Out[24]: array([0.16933861, 1.38188202])

    # what I really have in memory are these, can I compute the eigenvalues with numpy without copy?
    cov_00 = np.array([cov[0,0]])
    cov_01 = np.array([cov[0,1]])
    cov_11 = np.array([cov[1,1]])


    I am open to numba, the numpy docs for this routine show


    The eigenvalues are computed using LAPACK routines _syevd, _heevd.
    ​

    Would I be able to call those directly in the jit compiled routine? Would it save me the copy?

    Continue reading...

Compartilhe esta Página