Python Forum

Full Version: Cross-correlation between 2 planes in a 3D array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Python forum
I am trying create a 2D out that is the cross correlation between y-z planes
[Image: solSgIF.png]

I wrote this code, which doesn't work
import numpy as np
from scipy import signal
import scipy as ssc
np.random.seed(0)
data=np.random.rand(32,32,8192)


#z, y, x = data[:,0,0],data[0,:,0],data[0,0,:]
z=data[:,0,:]
y=data[0,:,:]      
Cyz=np.ones((32,32)) 
Cyz1=np.ones((32,32))                         #allocating matrix


for i in range(32):
            Cyz[i,i] = np.corrcoef(y[i,i],z[i,i]) # cross correlation                           
for i in range(32):
            Cyz1[i,i] =ssc.signal.correlate2d(y[i,i],z[i,i]) 
If you are familiar with any of these two functions, please, could you tell me what I am doing wrong?
Or if you think there is a better way/easier way I would appreciate that too.

Error:
Traceback (most recent call last): File "<ipython-input-33-dd850ca77ad0>", line 2, in <module> Cyz[i,i] = np.corrcoef(y[i,i],z[i,i]) # cross correlation ValueError: setting an array element with a sequence.
Thank you!
BR Mark
Dear Mark,

I think I know the source of this problem. I have an identical problem now. Did you find any solution to this problem?
If so, could you share? I would be eternally grateful.

Kind regards,
mats_snaps
Hi Mat_snaps

Unfortunately I couldn't figure it out, so I just gave up on it. If you figure it out you are very welcome to post your solution :)!

BR Mark