<div dir="ltr">On Thu, Nov 2, 2017 at 6:56 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">On Thu, Nov 2, 2017 at 8: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"><span class="gmail-"><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">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><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-m_-6438670014531177530gmail-"><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>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><br></div><div>How do you concatenate and operate arrays with different units?</div><div><br></div><div>interpolation or prediction would work with using the existing units.</div><div><br></div><div>partially related:</div><div>statsmodels uses a wrapper for pandas Series and DataFrames and tries to preserve the index when possible and make up a new DataFrame or Series if the existing index doesn't apply.</div><div>E.g. predicted values and residuals are in terms of the original provided index, and could also get original units assigned. That would also be possible with prediction confidence intervals. But for the rest, see above.</div></div></div></div></blockquote><div><br></div></span><div>using pint</div><div><br></div><div><div>>>> x</div><div><Quantity([0 1 2 3 4], 'meter')></div></div><div><div>>>> x / x</div><div><Quantity([ nan 1. 1. 1. 1.], 'dimensionless')></div><div><br></div><div>>>> x / (1 + x)</div><div>Traceback (most recent call last):</div><div> File "<stdin>", line 1, in <module></div><div> File "C:\...\python-3.4.4.amd64\<wbr>lib\site-packages\pint\<wbr>quantity.py", line 669, in __add__</div><div> raise DimensionalityError(self._<wbr>units, 'dimensionless')</div><div> return self._add_sub(other, operator.add)</div><div> File "C:\...\python-3.4.4.amd64\<wbr>lib\site-packages\pint\<wbr>quantity.py", line 580, in _add_sub</div><div>pint.errors.<wbr>DimensionalityError: Cannot convert from 'meter' to 'dimensionless'</div></div></div></div></div></blockquote><div><br></div><div>I'm not sure why you have a problem with that results. You tried to take a number in meters and add a dimensionless value to that--that's not a defined operation. That's like saying: "I have a distance of 12 meters and added 1 to it." 1 what? 1 meter? Great. 1 centimeter? I need to convert, but I can do that operation. 1 second? That makes no sense.</div><div><br></div><div>If you add units to the 1 then it's a defined operation:</div><div><br></div><div>>>> reg = pint.UnitRegistry()</div><div><div>>>> x / (1 * ureg.meters + x)</div><div><Quantity([ 0. 0.5 0.66666667 0.75 0.8 ], 'dimensionless')></div></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>np.exp(x) </div><div>raises<br></div><div>pint.errors.<wbr>DimensionalityError: Cannot convert from 'meter' ([length]) to 'dimensionless' (dimensionless)</div></div></div></div></div></blockquote><div><br></div><div>Well, the Taylor series for exp (around a=0) is:</div><div><br></div><div>exp(x) = 1 + x + x**2 / 2 + x**3 / 6 + ...</div><div><br></div><div>so for that to properly add up, x needs to be dimensionless. It should be noted, though, that I've *never* seen a formula, theoretically derived or empirically fit, require directly taking exp(x) where x is a physical quantity with units. Instead, you have:</div><div><br></div><div>f = a * exp(kx)</div><div><br></div><div>Properly calculated values for a, k will have appropriate units attached to them that allows the calculation to proceed without error</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>