You cannot do that: you have changed a global state: the way numpy deals with invalid division. Thus you have a big side effect.

You should write:
<pre>
with np.errstate(divide='ignore'):
     pvals_mat = ...
</pre>