Python Forum
3D covariance matrix - vectrorizing python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D covariance matrix - vectrorizing python
#1
I need to speed up a python code, I would like to avoid the use of the following for cycle, where "data" matrix has dimension [dim1xdim2]:

for i in range(int(dim1)):
        data_process = data[i,:].reshape((dim2, 1))
        rxx = data_process * np.matrix.getH(np.asmatrix(data_process)) / dim2
Using the 'for cycle' the dimension of the rxx matrix is [dim2xdim2], I would get a 3D "rxx" matrix [dim1xdim2xdim2]. I tried to use the following solution:

data_new = repeat(data_process0[:, :, newaxis], dim2, axis=2)
 N_2 = data_new.shape[2]
 m1 = data_new - data_new.sum(2, keepdims=1) / N_2
 y_out = einsum('ijk,ilk->ijl', m1, m1) / (N_2 - 1)
In this case I got 3D "y_out" matrix [dim1xdim2xdim2] but this doesn't work in my case.

Thanks,
Luca
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with Python Script to generate SVG Dot Matrix Pattern for LED Light Guide iamrickm 2 751 Aug-25-2023, 06:07 PM
Last Post: iamrickm
  Check if two matrix are equal and of not add the matrix to the list quest 3 820 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,353 May-03-2021, 06:30 AM
Last Post: Gribouillis
  Matrix Operations Without Numpy or Incorporating Python into Webpage ebryski 1 2,897 Nov-26-2020, 12:50 PM
Last Post: jefsummers
  Covariance Matrix - Python cesardepaula 2 5,369 Mar-08-2019, 07:45 AM
Last Post: cesardepaula
  matrix from matrix python numpy array shei7141 1 3,687 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020