Python programming - numpy polyfit saying NAN

前端 未结 1 683
闹比i
闹比i 2021-01-12 06:30

I am having some issues with a pretty simple code I have written. I have 4 sets of data, and want to generate polynomial best fit lines using numpy polyfit. 3 of the lists y

相关标签:
1条回答
  • 2021-01-12 07:35

    Just looked at your data. This is happening because you have a NaN in dep_3 (element 713). You can make sure that you only use finite values in the fit like this:

    idx = np.isfinite(ind_3) & np.isfinite(dep_3)
    print(np.polyfit(ind_3[idx], dep_3[idx], 2))
    

    As for finding for bad values in large datasets, numpy makes that really easy. You can find the indices like this:

    print(np.where(~np.isfinite(dep_3)))
    
    0 讨论(0)
提交回复
热议问题