My array is a 2D matrix and it has numpy.nan values besides negative and positive values:
>>> array array([[ nan, nan, nan, ...,
Try:
a[a>0] = 1 a[a<0] = -1