changed nan handling to neg, because of dtype problem in numpy