This code is quite slow in Python. How can I optimize this using numpy. The array m and z are already numpy arrays but I assume I need to vectorize this somehow though I can't find an example where the vectorized function also has access to the value coordinates.
for i in xrange(states):
for j in xrange(states):
if i != j and z[i, j] != 0 and m[i, j] < 0.0:
m[i, i] += m[i, j]
m[i, j] = 0.0
z[i, j] = 0