[Tutor] location of points in a covariance matrix
Beanan O Loughlin
beanan.o.loughlin at gmail.com
Wed Jul 25 00:40:19 CEST 2007
Hi all, I'm a meteorology postgrad working with python for the first time.
I have found the location minimum in a large covariance matrix. this value
corresponds to the covariance of two points on a latitude, longitude grid.
I need to find a method to locate these two points on the lat,lon grid.
this is the code i have used, where 'se' is a 3-D array of data
>>> nt,nlat,nlon = shape(se)
>>>nt,nlat,nlon # 3-D array of data taken 1464
times, over 41 latitudes and 58 longitudes
(1464, 41, 58)
>>>
>>>
>>>m=reshape(se,(nt,nlat*nlon)) # reshape to (time,latitude longitude
data point) where 2378 = 41*58
>>>
>>>shape(m)
(1464,2378)
>>>
>>>
>>>covmat=cov(m) # calculate covariance matrix
>>>
>>>shape(covmat)
(2378,2378)
>>>def min(R):
U = triu(R) #just use one half of the
diagonal matrix
n = U.shape[0]
U.flat[::n+1] = 1000000000.0 #give the diagonal elements a large
value so they wont be selected
k = argmin(U.flat) #find the min value of the
flattened array
i, j = divmod(k,n) #calculate the index of the
minimum data
return i, j, R[i,j]
>>>
>>> min(covmat)
(7, 1914, -2.3016361721151051)
so the minimum is found at (7,1914) in the covariance matrix and has a value
of -2.3
This min point corresponds to the covariance between two 'lat,lon' data
points in my (41,58) sample grid.
Is there a way i can move back from my (2378,2378) covariance matrix to see
where these two points are located on the (41, 58) grid?
Thank you very much in advance
B.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070724/1884bb5c/attachment.htm
More information about the Tutor
mailing list