0

I have to create numbers for an x axis, first number equaling the minimum of my data set, and after that the numbers should increment by 0.001, until it equals the maximum of my data set. for some reason the numbers change in an unexpected way at the 15th decimal and I don't understand why.

def define_grid(data):
    j = float(min(data))
    xgrid = np.empty([0, 1])
    while j < max(data):
        xgrid = np.append(xgrid, j)
        j = j + 0.001
    else:
        xgrid = np.append(xgrid, j)
    return xgrid

for i in grid1:
    print(i)

-21.74107816833327 -21.74007816833327 -21.73907816833327 -21.738078168333267 -21.737078168333266 -21.736078168333265

mitch
  • 1
  • Look into [numpy.arange](https://numpy.org/doc/stable/reference/generated/numpy.arange.html#numpy.arange) or [numpy.linspace](https://numpy.org/doc/stable/reference/generated/numpy.linspace.html) to construct your grid without using a loop. – John Coleman Jan 25 '23 at 16:10

0 Answers0