R. Baptista
R. Baptista

Reputation: 21

ValueError: object of too small depth for desired array

I've searched and find out this may be a problem concerning types. But I tried to force the array to float using astype didn't work out. This must be a simple error, however im a beginner. About the problem: im trying to form the spatial correlation matrix bewteen the signals of all mics.

 R_a[k][l] = np.correlate(self.mic_list[k].delayed_signal,self.mic_list[l].delayed_signal)

where this class has a mic_list which is a list of mic, which is another class that has this method

def add_delayed_signal (self, delayed_signal):
    self.delayed_signal = delayed_signal

Thanks you in advanced.

Upvotes: 1

Views: 1884

Answers (1)

Praveen
Praveen

Reputation: 7222

I'm guessing R_a is a 2-dimensional array. What np.correlate does is to compute the cross-correlation between two signals, and gives you a vector as a result (not a scalar).

What you're looking for is probably np.cov or np.corrcoef. These are also vectorized approaches to getting the result you want.

For example:

>>> x = np.random.randn(10)
>>> y = np.random.randn(10)
>>> X = np.vstack((x, y))
>>> X
array([[ 1.45841294, -0.16430013, -0.20782822,  0.08979425, -1.38337166,
         0.36488053, -2.57135737,  0.81215918, -0.54081983,  0.30421112],
       [-0.79416305,  1.14511318, -0.4962483 , -0.42647021, -0.59925241,
        -0.45612051, -0.02566026, -1.7668091 , -1.63098627,  0.3761437 ]])
>>> np.cov(X)    
array([[ 1.28563113, -0.20563105],
       [-0.20563105,  0.74178773]])

Is this what you're looking for?

Upvotes: 1

Related Questions