<div dir="ltr">Like Nathaniel said, it would not improve much when compared to the modulo operator. <div><br></div><div>It could handle the edge cases better, but really the biggest benefit would be that it is more convenient.</div><div><br></div><div>And as the "unwrap" function already exists, people would expect that and look for a function for the inverse operation (at least I did).</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 24 Nov 2020 at 09:22, Daniele Nicolodi <<a href="mailto:daniele@grinta.net">daniele@grinta.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 24/11/2020 02:49, Nathaniel Smith wrote:<br>
> How would this proposed function compare to using the modulo operator,<br>
> like 'arr % (2*pi)'?<br>
<br>
I wrote almost the same word bu word reply, before realizing that taking<br>
the modulo looses the sign. The correct operation is slightly more<br>
complex (untested):<br>
<br>
def wrap(alpha):<br>
return (alpha + np.pi) % 2.0 * np.pi - np.pi<br>
<br>
However, I don't think there is much value in adding something so<br>
trivial as a function to numpy: I cannot think to any commonly used<br>
algorithm that requires wrapping the phase, and it is going to be an<br>
infinite source of bikesheeding whether the wrapped range should be<br>
[-pi, pi) or (-pi, pi] or (0, 2*pi] or [0, 2*pi)<br>
<br>
Cheers,<br>
Dan<br>
<br>
<br>
> On Mon, Nov 23, 2020, 16:13 Thomas <<a href="mailto:thomasbbrunner@gmail.com" target="_blank">thomasbbrunner@gmail.com</a><br>
> <mailto:<a href="mailto:thomasbbrunner@gmail.com" target="_blank">thomasbbrunner@gmail.com</a>>> wrote:<br>
> <br>
> Hi,<br>
> <br>
> I have a proposal for a feature and I hope this is the right place<br>
> to post this.<br>
> <br>
> The idea is to have a function to map any input angle to the range<br>
> of [ 0, 2*pi ] or [ - pi, pi ].<br>
> <br>
> There already is a function called 'unwrap' that does the opposite,<br>
> so I'd suggest calling this function 'wrap'.<br>
> <br>
> Example usage:<br>
> # wrap to range [ 0, 2*pi ]<br>
> >>> np.wrap([ -2*pi, -pi, 0, 4*pi ])<br>
> [0, pi, 0, 2*pi]<br>
> <br>
> There is some ambiguity regarding what the solution should be for<br>
> the extremes. An example would be an input of 4*pi, as both 0 and<br>
> 2*pi would be valid mappings.<br>
> <br>
> There has been interest for this topic in the community<br>
> (see <a href="https://stackoverflow.com/questions/15927755/opposite-of-numpy-unwrap" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/15927755/opposite-of-numpy-unwrap</a><br>
> <<a href="https://stackoverflow.com/questions/15927755/opposite-of-numpy-unwrap" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/15927755/opposite-of-numpy-unwrap</a>>).<br>
> <br>
> Similar functions exist for Matlab<br>
> (see <a href="https://de.mathworks.com/help/map/ref/wrapto2pi.html" rel="noreferrer" target="_blank">https://de.mathworks.com/help/map/ref/wrapto2pi.html</a><br>
> <<a href="https://de.mathworks.com/help/map/ref/wrapto2pi.html" rel="noreferrer" target="_blank">https://de.mathworks.com/help/map/ref/wrapto2pi.html</a>>). They solved<br>
> the ambiguity by mapping "positive multiples of 2*pi map to 2*pi and<br>
> negative multiples of 2*pi map to 0." for the 0 to 2*pi case.<br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a> <mailto:<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>
> <<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>
> <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>
<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>
</blockquote></div>