Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: pysal explanation of weight function

Tags:

python

2d

pysal

I have a 2D array of values and I'm trying to analyze spatial correlations. To calculate a 2D autocorrelation like Moran's I in python, pysal provides an implementation. 1) How do I transform my 2D data into a 1D array expected by pysal? 2) How do I construct a weight array w that is based on distance (what does the input array of points mean in the Kernel distance function?)?

like image 791
user3450049 Avatar asked Oct 16 '25 15:10

user3450049


1 Answers

1) The weights array should be flattened in the same way as you flatten the data array. The order doesn't matter, as long as the indices agree.

2) The input array can be spatial coordinates (e.g. x and y, or lat and long). By far the easiest are the indices of your original matrix (e.g. 1 to n times 1 to m).

In the end, your data will be a list with 3 elements: x, y and value. Your weights will be a list with 5 elements: x_from, y_from, x_to, y_to and weight.

like image 181
LBogaardt Avatar answered Oct 18 '25 09:10

LBogaardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!