1

For some reason, my data reduction for a fits image has given me -0 values, which I would like to set to 0.

I've attempted to use:

my_array[~numpy.isfinite(my_array)] = 0

All I would like to do is set the -0 values in the corrfact_um2_ext1 array to 0. Just to keep everything in the same format, as I think this may cause a problem in subsequent data reduction steps.

But this just deals with NaN values and sets them to 0. So, I'm halfway there!

GCien
  • 2,221
  • 6
  • 30
  • 56
  • 2
    Possible duplicate of [How to eliminate the extra minus sign when rounding negative numbers towards zero in numpy?](http://stackoverflow.com/questions/26782038/how-to-eliminate-the-extra-minus-sign-when-rounding-negative-numbers-towards-zer) – runDOSrun Feb 15 '16 at 17:02
  • How did you manage to even get -0? – Alex McLean Feb 15 '16 at 17:02
  • 1
    I don't even know! :) I used scipy.ndimage.filters.uniform_filter() – GCien Feb 15 '16 at 17:04

1 Answers1

1

Simply adding 0.0 to each floating point number should fix this:

a = np.array([-0.0, 0.0, 1.0, -1.0])
Out[1]: array([-0.,  0.,  1., -1.]

a += 0.0
a
Out[2]: array([ 0.,  0.,  1., -1.])

But note:

np.array(-0.) == np.array(+0.)
Out[3]: True

Does this solve your problem?

meltdown90
  • 251
  • 1
  • 11