OD_weights
import pysal as ps
from pysal import weights as w
import numpy as np
import scipy.sparse as sp
def OD(Wo, Wd):
Wo = Wo.sparse
Wd = Wd.sparse
Ww = sp.kron(Wo, Wd)
return w.WSP2W(w.WSP(Ww))
origins = ps.weights.lat2W(4,4)
dests = ps.weights.lat2W(4,4)
Ww = OD(origins, dests)
Ww.transform = 'r'
print Ww.full()[0].shape
flows = np.random.randint(0,100, (4,4))
np.fill_diagonal(flows, 0)
flows = flows.reshape((16,1))
print flows
slag = ps.lag_spatial(Ww, flows)
print slag
origins.weights
import os
os.chdir('/Users/toshan/dev/pysal/pysal/weights')
from spintW import ODW
origins = ps.weights.lat2W(2,2)
dests = ps.weights.lat2W(2,2)
Ww = ODW(origins, dests)
Ww.full()[0]