<div dir="ltr">On Thu, Nov 2, 2017 at 6:46 AM, <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">On Wed, Nov 1, 2017 at 6:55 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I think the biggest issues could be resolved if __array_concatenate__ were finished. Unfortunately I don't feel like I can take that on right now.<br><br></div>See Ryan May's talk at scipy about using an ndarray subclass for units and the issues he's run into:<br><br><a href="https://www.youtube.com/watch?v=qCo9bkT9sow" target="_blank">https://www.youtube.com/watch?<wbr>v=qCo9bkT9sow</a></div></blockquote><div><br></div><div><br></div></span><div>Interesting talk, but I don't see how general library code should know what units the output has.</div><div>for example if units are some flows per unit of time and we average, sum or integrate over time, then what are the new units? (e.g. pandas time aggregation)</div><div></div></div></div></div></blockquote><div><br></div><div>A general library doesn't have to do anything--just not do annoying things like isinstance() checks and calling np.asarray() everywhere. Honestly one of those is the core of most of the problems I run into. It's currently more complicated when doing things in compiled land, but that's implementation details, not any kind of fundamental incompatibility.</div><div><br></div><div>For basic mathematical operations, units have perfectly well defined semantics that many of us encountered in an introductory physics or chemistry class:</div><div>- Want to add or subtract two things? They need to have the same units; a units library can handle conversion provided they have the same dimensionality (e.g. length, time)</div><div>- Multiplication/Divison: combine and cancel units ( m/s * s -> m)</div><div><br></div><div>Everything else we do on a computer with data in some way boils down to: add, subtract, multiply, divide.</div><div><br></div><div>Average keeps the same units -- it's just a sum and division by a unit-less constant</div><div>Integration (in 1-D) involves *two* variables, your data as well as the time/space coordinates (or dx or dt); fundamentally it's a multiplication by dx and a summation. The units results then are e.g. data.units * dx.units. This works just like it does in Physics 101 where you integrate velocity (i.e. m/s) over time (e.g. s) and get displacement (e.g. m)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>What are units of covariance or correlation between two variables with the same units, and what are they between variables with different units?</div></div></div></div></blockquote><div><br></div><div>Well, covariance is subtracting the mean from each variable and multiplying the residuals; therefore the units for cov(x, y):</div><div><br></div><div>(x.units - x.units) * (y.units - y.units) -> x.units * y.units</div><div><br></div><div>Correlation takes covariance and divides by the product of the standard deviations, so that's:<br></div><div><br></div><div>(x.units * y.units) / (x.units * y.units) -> dimensionless</div><div><br></div><div>Which is what I'd expect for a correlation.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>How do you concatenate and operate arrays with different units?</div></div></div></div></blockquote><div><br></div><div>If all arrays have compatible dimensionality (say meters, inches, miles), you convert to one (say the first) and concatenate like normal. If they're not compatible, you error out.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>interpolation or prediction would work with using the existing units.</div></div></div></div></blockquote><div><br></div><div>I'm sure you wrote that thinking units didn't play a role, but the math behind those operations works perfectly fine with units, with things cancelling out properly to give the same units out as in.</div><div><br></div><div>Ryan</div><div><br></div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Ryan May<br><br></div></div></div>
</div></div>