<div dir="ltr"><div class="markdown-here-wrapper" style=""><blockquote style="margin:1.2em 0px;border-left:4px solid rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em!important">Can’t arange and linspace operations with floats be done internally</p>
</blockquote>
<p style="margin:0px 0px 1.2em!important">Yes, and they probably should be - they’re done this way as a hack because the api exposed for custom dtypes is <a href="https://github.com/numpy/numpy/blob/81e15e812574d956fcc304c3982e2b59aa18aafb/numpy/core/include/numpy/ndarraytypes.h#L507-L511">here</a>, (example implementation <a href="https://github.com/numpy/numpy/blob/81e15e812574d956fcc304c3982e2b59aa18aafb/numpy/core/src/multiarray/arraytypes.c.src#L3711-L3721">here</a>) - essentially, you give it the first two elements of the array, and ask it to fill in the rest.</p>
<div title="MDH:Jmd0O8KgPHNwYW4gc3R5bGU9ImNvbG9yOiByZ2IoMzMsIDMzLCAzMyk7Ij5DYW4ndCBhcmFuZ2Ug
YW5kIGxpbnNwYWNlIG9wZXJhdGlvbnMgd2l0aCBmbG9hdHMgYmUgZG9uZSBpbnRlcm5hbGx5PGJy
Pjxicj5ZZXMsIGFuZCB0aGV5IHByb2JhYmx5IHNob3VsZCBiZSAtIHRoZXkncmUgZG9uZSB0aGlz
IHdheSBhcyBhIGhhY2sgYmVjYXVzZSB0aGUgYXBpIGV4cG9zZWQgZm9yIGN1c3RvbSBkdHlwZXMg
aXMgW2hlcmVdKDwvc3Bhbj48Zm9udCBjb2xvcj0iIzIxMjEyMSI+PGEgaHJlZj0iaHR0cHM6Ly9n
aXRodWIuY29tL251bXB5L251bXB5L2Jsb2IvODFlMTVlODEyNTc0ZDk1NmZjYzMwNGMzOTgyZTJi
NTlhYTE4YWFmYi9udW1weS9jb3JlL2luY2x1ZGUvbnVtcHkvbmRhcnJheXR5cGVzLmgjTDUwNy1M
NTExIj5odHRwczovL2dpdGh1Yi5jb20vbnVtcHkvbnVtcHkvYmxvYi84MWUxNWU4MTI1NzRkOTU2
ZmNjMzA0YzM5ODJlMmI1OWFhMThhYWZiL251bXB5L2NvcmUvaW5jbHVkZS9udW1weS9uZGFycmF5
dHlwZXMuaCNMNTA3LUw1MTE8L2E+KSwgKGV4YW1wbGUgaW1wbGVtZW50YXRpb24gW2hlcmVdKDxh
IGhyZWY9Imh0dHBzOi8vZ2l0aHViLmNvbS9udW1weS9udW1weS9ibG9iLzgxZTE1ZTgxMjU3NGQ5
NTZmY2MzMDRjMzk4MmUyYjU5YWExOGFhZmIvbnVtcHkvY29yZS9zcmMvbXVsdGlhcnJheS9hcnJh
eXR5cGVzLmMuc3JjI0wzNzExLUwzNzIxIj5odHRwczovL2dpdGh1Yi5jb20vbnVtcHkvbnVtcHkv
YmxvYi84MWUxNWU4MTI1NzRkOTU2ZmNjMzA0YzM5ODJlMmI1OWFhMThhYWZiL251bXB5L2NvcmUv
c3JjL211bHRpYXJyYXkvYXJyYXl0eXBlcy5jLnNyYyNMMzcxMS1MMzcyMTwvYT4pKSAtIGVzc2Vu
dGlhbGx5LCB5b3UgZ2l2ZSBpdCB0aGUgZmlyc3QgdHdvIGVsZW1lbnRzIG9mIHRoZSBhcnJheSwg
YW5kIGFzayBpdCB0byBmaWxsIGluIHRoZSByZXN0LjwvZm9udD48ZGl2Pjxicj48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 9 Feb 2018 at 13:17 Matthew Harrigan <<a href="mailto:harrigan.matthew@gmail.com">harrigan.matthew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I apologize if I'm missing something basic, but why are floats being accumulated in the first place?  Can't arange and linspace operations with floats be done internally similar to `start + np.arange(num_steps) * step_size`?  I.e. always accumulate (really increment) integers to limit errors.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 9, 2018 at 3:43 PM, Benjamin Root <span dir="ltr"><<a href="mailto:ben.v.root@gmail.com" target="_blank">ben.v.root@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Fri, Feb 9, 2018 at 12:19 PM, Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-">On Wed, Feb 7, 2018 at 12:09 AM, Ralf Gommers <span dir="ltr"><<a href="mailto:ralf.gommers@gmail.com" target="_blank">ralf.gommers@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div> It is partly a plea for some development of numerically accurate functions for computing lat/lon grids from a combination of inputs: bounds, counts, and resolutions.</div></div></div></blockquote></span></div></div></div></blockquote><div><br></div></span><div>Can you be more specific about what problems you've run into -- I work with lat-lon grids all the time, and have never had a problem.</div><div><br></div><div>float32 degrees gives you about 1 meter accuracy or better, so I can see how losing a few digits might be an issue, though I would argue that you maybe shouldn't use float32 if you are worried about anything close to 1m accuracy... -- or shift to a relative coordinate system of some sort.</div></div></div></div></blockquote><div><br></div></span><div>The issue isn't so much the accuracy of the coordinates themselves. I am only worried about 1km resolution (which is approximately 0.01 degrees at mid-latitudes). My concern is with consistent *construction* of a coordinate grid with even spacing. As it stands right now. If I provide a corner coordinate, a resolution, and the number of pixels, the result is not terrible (indeed, this is the approach used by gdal/rasterio). If I have start/end coordinates and the number of pixels, the result is not bad, either (use linspace). But, if I have start/end coordinates and a resolution, then determining the number of pixels from that is actually tricky to get right in the general case, especially with float32 and large grids, and especially if the bounding box specified isn't exactly divisible by the resolution.<br> </div><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>I have been playing around with the decimal package a bit lately,</div></div></div></blockquote></span></div></div></div></blockquote><div><br></div></span><div>sigh. decimal is so often looked at a solution to a problem it isn't designed for. lat-lon is natively Sexagesimal -- maybe we need that dtype :-)</div><div><br></div><div>what you get from decimal is variable precision -- maybe a binary variable precision lib is a better answer -- that would be a good thing to have easy access to in numpy, but in this case, if you want better accuracy in a computation that will end up in float32, just use float64.</div></div></div></div></blockquote><div><br></div></span><div>I am not concerned about computing distances or anything like that, I am trying to properly construct my grid. I need consistent results regardless of which way the grid is specified (start/end/count, start/res/count, start/end/res). I have found that loading up the grid specs (using in a config file or command-line) using the Decimal class allows me to exactly and consistently represent the grid specification, and gets me most of the way there. But the problems with arange() is frustrating, and I have to have extra logic to go around that and over to linspace() instead.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>and I discovered the concept of "fused multiply-add" operations for improved accuracy. I have come to realize that fma operations could be used to greatly improve the accuracy of linspace() and arange().</div></div></div></blockquote></span></div></div></div></blockquote><div><br></div></span><div>arange() is problematic for non-integer use anyway, by its very definition (getting the "end point" correct requires the right step, even without FP error).</div><div><br></div><div>and would it really help with linspace? it's computing a delta with one division in fp, then multiplying it by an integer (represented in fp -- why? why not keep that an integer till the multiply?).</div></div></div></div></blockquote><div><br></div></span><div>Sorry, that was a left-over from a previous draft of my email after I discovered that linspace's accuracy was on par with fma(). And while arange() has inherent problems, it can still be made better than it is now. In fact, I haven't investigated this, but I did recently discover some unit tests of mine started to fail after a numpy upgrade, and traced it back to a reduction in the accuracy of a usage of arange() with float32s. So, something got worse at some point, which means we could still get accuracy back if we can figure out what changed.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>In particular, I have been needing improved results for computing latitude/longitude grids, which tend to be done in float32's to save memory (at least, this is true in data I come across).<br></div></div></div></blockquote><div><br></div></span><div>If you care about saving memory *and* accuracy, wouldn't it make more sense to do your computations in float64, and convert to float32 at the end? </div></div></div></div></blockquote><div><br></div></span><div>that does seem to be the easy option :-)</div></div></div></div></blockquote><div><br></div></span><div>Kinda missing the point, isn't it? Isn't that like saying "convert all your data to float64s prior to calling np.mean()"? That's ridiculous. Instead, we made np.mean() upcast the inner-loop operation, and even allow an option to specify what the dtype that should be used for the aggregator.<br> <br></div><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-h5"><div dir="ltr"><div><div>Now, to the crux of my problem. It is next to impossible to generate a non-trivial numpy array of coordinates, even in double precision, without hitting significant numerical errors.</div></div></div></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>I'm confused, the example you posted doesn't have significant errors...</div></div></div></div></blockquote><div><br></div></span><div>Hmm, "errors" was the wrong word. "Differences between methods" might be more along the lines of what I was thinking. Remember, I am looking for consistency.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-h5"><div dir="ltr"><div><div>Which has lead me down the path of using the decimal package (which doesn't play very nicely with numpy because of the lack of casting rules for it). Consider the following:<br></div></div><div>```</div><div>$ cat test_fma.py<br>from __future__ import print_function<br>import numpy as np<br>res = np.float32(0.01)<br>cnt = 7001<br>x0 = np.float32(-115.0)<br>x1 = res * cnt + x0<br>print("res * cnt + x0 = %.16f" % x1)<br>x = np.arange(-115.0, -44.99 + (res / 2), 0.01, dtype='float32')<br>print("len(arange()): %d  arange()[-1]: %16f" % (len(x), x[-1]))<br>x = np.linspace(-115.0, -44.99, cnt, dtype='float32')<br>print("linspace()[-1]: %.16f" % x[-1])<br><br>$ python test_fma.py<br>res * cnt + x0 = -44.9900015648454428<br>len(arange()): 7002  arange()[-1]:       -44.975044<br>linspace()[-1]: -44.9900016784667969</div><div>```</div><div>arange just produces silly results (puts out an extra element... adding half of the resolution is typically mentioned as a solution on mailing lists to get around arange()'s limitations -- I personally don't do this).</div></div></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>The real solution is "don't do that" arange is not the right tool for the job.</div></div></div></div></blockquote><div><br></div></span><div>Well, it isn't the right tool because as far as I am concerned, it is useless for anything but integers. Why not fix it to be more suitable for floating point?<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Then there is this:</div><div><br></div><div><span class="m_-7149791136508986733m_7132347947710566704gmail-">res * cnt + x0 = -44.9900015648454428<br></span>linspace()[-1]: -44.9900016784667969<br></div><div><br></div><div>that's as good as you are ever going to get with 32 bit floats...</div></div></div></div></blockquote><div><br></div></span><div>Consistency is the key thing. I am fine with one of those values, so long as that value is what happens no matter which way I specify my grid.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Though I just noticed something about your numbers -- there should be a nice even base ten delta if you have 7001 gaps -- but linspace produces N points, not N gaps -- so maybe you want:</div><div><br></div><div>







<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>17</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">l = np.linspace(-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">115.0</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, -</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">44.99</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">7002</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>18</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[:</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">]</span></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>18</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-115.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">  </span>, -114.99, -114.98, -114.97, -114.96])</span></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>19</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:]</span></p>
<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>19</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-45.03, -45.02, -45.01, -45.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">  </span>, -44.99])</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">or, in float32 -- not as pretty:</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>20</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">l = np.linspace(-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">115.0</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, -</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">44.99</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">7002</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, dtype=np.float32)</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>21</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[:</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">]</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>21</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]:<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space"> </span></span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-115.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">        </span>, -114.98999786, -114.98000336, -114.97000122,</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">       </span>-114.95999908], dtype=float32)</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>22</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:]</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>22</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-45.02999878, -45.02000046, -45.00999832, -45.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">        </span>, -44.99000168], dtype=float32)</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">

















</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>but still as good as you get with float32, and exactly the same result as computing in float64 and converting:<p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>25</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">l = np.linspace(-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">115.0</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, -</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">44.99</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">, </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">7002</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">).astype(np.float32)</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>26</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[:</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">]</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(178,54,34);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>26</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]:<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space"> </span></span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-115.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">        </span>, -114.98999786, -114.98000336, -114.97000122,</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">       </span>-114.95999908], dtype=float32)</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>27</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">l[-</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">5</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:]</span></p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px">
















</p><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>27</b></span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-s1" style="font-variant-ligatures:no-common-ligatures">array([-45.02999878, -45.02000046, -45.00999832, -45.<span class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-Apple-converted-space">        </span>, -44.99000168], dtype=float32)</span></p></div></div></div></div></blockquote><div><br></div></span><div>Argh! I got myself mixed up between specifying pixel corners versus pixel centers. rasterio has been messing me up on this.<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><p class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><br></p></div><span class="m_-7149791136508986733m_7132347947710566704gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-h5"><div dir="ltr"><div><br></div><div>So, does it make any sense to improve arange by utilizing fma() under the hood?</div></div></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>no -- this is simply not the right use-case for arange() anyway.</div></div></div></div></blockquote><div><br></div></span><div>arange() has accuracy problems, so why not fix it?<br><br>>>> l4 = np.arange(-115, -44.99, 0.01, dtype=np.float32)<br>>>> np.median(np.diff(l4))<br>0.0099945068<br>>>> np.float32(0.01)<br>0.0099999998<br><br></div><div>There is something significantly wrong here if arange(), which takes a resolution parameter, can't seem to produce a sequence with the proper delta.<br><br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-h5"><div dir="ltr"><div> Also, any plans for making fma() available as a ufunc?</div></div></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>could be nice -- especially if used internally.</div><span class="m_-7149791136508986733m_7132347947710566704gmail-"><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-7149791136508986733m_7132347947710566704gmail-m_7573092184603669867gmail-m_5395870394381385280gmail-h5"><div dir="ltr"><div>Notice that most of my examples required knowing the number of grid points ahead of time. But what if I didn't know that? What if I just have the bounds and the resolution? Then arange() is the natural fit, but as I showed, its accuracy is lacking, and you have to do some sort of hack to do a closed interval.</div></div></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>no -- it's not -- if you have the bounds and the resolution, you have an over-specified problem. That is:</div><div><br></div><div>x_min + (n * delta_x) == x_max</div><div><br></div><div>If there is ANY error in either delta_x or x_max (or x_min), then you'll get a missmatch. which is why arange is not the answer (you can make the algorithm a bit more accurate, I suppose but there is still fp limited precision -- if you can't exactly represent either delta_x or x_max, then you CAN'T use the arange() definition and expect to work consistently.</div><div><br></div><div>The "right" way to do it is to compute N with: round((x_max - x_min) / delta), and then use linspace:</div><div><br></div><div>linspace(x_min, x_max, N+1)</div><div><br></div><div>(note that it's too bad you need to do N+1 -- if I had to do it over again, I'd use N as the number of "gaps" rather than the number of points -- that's more commonly what people want, if they care at all)</div><div><br></div><div>This way, you get a grid with the endpoints as exact as they can be, and the deltas as close to each-other as they can be as well.</div><div><br></div><div>maybe you can do a better algorithm in linspace to save an ULP, but it's hard to imagine when that would matter.</div></div></div></div></blockquote><div><br></div></span><div>Yes, it is overspecified. My problem is that different tools require different specs (ahem... rasterio/gdal), and I have gird specs coming from other sources. And I need to produce data onto the same grid so that tools like xarray won't yell at me when I am trying to do an operation between gridded data that should have the same coordinates, but are off slightly because they were computed differently for whatever reason.<br><br></div><div>I guess I am crying out for some sort of tool that will help the community stop making the same mistakes. A one-stop shop that'll allow us to specify a grid in a few different ways and still produce the right thing, and even do the inverse... provide a coordinate array and get grids specs in whatever form we want. Maybe even have options for dealing with pixel corner vs. pixel centers, too? There are additional fun problems such as padding out coordinate arrays, which np.pad doesn't really do a great job with.<br><br></div><div>Cheers!<br></div><div>Ben Root<br></div></div></div></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>