Vote count:
0
I'm using the np.ma module to calculate Covariance of two overlapping image arrays that have noData value present in them. The code goes as follows:
import numpy as np
arr1 = np.array([1638,1753,1601,1819,-9999,1627,1400,1379,1055])
arr2 = np.array([-9999,1455,1973,1330,1915,1842,1816,1218,-9999])
images = np.vstack((arr1.ravel(),arr2.ravel()))
images = np.ma.array(images , mask=images ==-9999)
cov_mat = np.ma.cov(images ,bias=True)
The output of the covariance matrix is :
[[53070.25 -8273.07142857143]
[-8273.07142857143 80860.40816326531]]
I have a issue with the result, the first value is calculated using arr1 and the number of observations equal to 8 (since there is only a single noData value). The last value is calculated using arr2 but the number of observations taken is 7 (Two noData values).
Is there a way to specify to the cov function to take only the maximum number of observations for division while calculating covariance or will I have to perform the operation manually?
asked 48 secs ago
Covariance Matrix with Mask - Python
Aucun commentaire:
Enregistrer un commentaire