0

The numpy polynomial fit function for masked arrays, ma.polyfit, crashes on integer iput:

import numpy.ma as ma
x = ma.arange(2)
y = ma.arange(2)
p1 = ma.polyfit(np.float32(x), y, deg=1)
p2 = ma.polyfit(           x , y, deg=1)

The last line results in an error:

ValueError: data type <type 'numpy.int64'> not inexact

Why can't I fit data with integer x-values (it's no problem with the normal numpy.polyfit function), is this a (known) bug?

Rolf Bartstra
  • 1,643
  • 1
  • 16
  • 19

1 Answers1

3

It is indeed a bug from numpy.ma : the rcond (a parameter to exclude some values ) takes len(x)*np.finfo(x.dtypes).eps as a default value, and np.int32 does not have any epsfield (because an int does not have a relative precision).

import numpy.ma as ma
eps = np.finfo(np.float32).eps 

x = ma.arange(2)
y = ma.arange(2)
p1 = ma.polyfit(np.float32(x), y, deg=1, rcond = len(x)*eps)
p2 = ma.polyfit(           x , y, deg=1, rcond = len(x)*eps)

I've looked quickly into numpy's issues, and this bug does not seems to figured there. It might be a good idea to raise a new issue : New Issue

lucasg
  • 10,734
  • 4
  • 35
  • 57