Hi, I have written some numpy tips and tricks I am using, which may be interesting to you. This is quite long reading, so I've splitted it into two parts: http://arogozhnikov.github.io/2015/09/29/NumpyTipsAndTricks1.html http://arogozhnikov.github.io/2015/09/30/NumpyTipsAndTricks2.html Comments are welcome, specially if you know any other ways to make this code faster (or better). Regards, Alex.
On 2015-10-01 11:46:59, Alex Rogozhnikov <alex.rogozhnikov@yandex.ru> wrote:
Hi, I have written some numpy tips and tricks I am using, which may be interesting to you. This is quite long reading, so I've splitted it into two parts:
http://arogozhnikov.github.io/2015/09/29/NumpyTipsAndTricks1.html http://arogozhnikov.github.io/2015/09/30/NumpyTipsAndTricks2.html
I think that's a nice list already! I would probably start with: %matplotlib inline import numpy as np Then port all the code to Python 3 (or at least Python 2 & 3 compatible). Perhaps some illustrations could be useful, e.g. how to use the IronTransform to do histogram equalization. Stéfan
On Thu, Oct 1, 2015 at 11:46 AM, Alex Rogozhnikov < alex.rogozhnikov@yandex.ru> wrote:
Hi, I have written some numpy tips and tricks I am using, which may be interesting to you. This is quite long reading, so I've splitted it into two parts:
http://arogozhnikov.github.io/2015/09/29/NumpyTipsAndTricks1.html
The recommendation of inverting a permutation by argsort'ing it, while it works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time: In [14]: import numpy as np In [15]: arr = np.random.rand(10) In [16]: perm = arr.argsort() In [17]: perm Out[17]: array([5, 0, 9, 4, 2, 8, 6, 7, 1, 3]) In [18]: inv_perm = np.empty_like(perm) In [19]: inv_perm[perm] = np.arange(len(perm)) In [20]: np.all(inv_perm == perm.argsort()) Out[20]: True It does require two lines of code, so for small stuff it is probably good enough to argsort, but it gave e.g. np.unique a nice boost on larger arrays when we applied it there. Jaime
http://arogozhnikov.github.io/2015/09/30/NumpyTipsAndTricks2.html
Comments are welcome, specially if you know any other ways to make this code faster (or better).
Regards, Alex.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
-- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
I would suggest %matplotlib notebook It will still have to a nice png, but you get an interactive figure when it is live. I agree that making the example code Python3 is critical. Tom On Thu, Oct 1, 2015 at 8:05 PM Jaime Fernández del Río <jaime.frio@gmail.com> wrote:
On Thu, Oct 1, 2015 at 11:46 AM, Alex Rogozhnikov < alex.rogozhnikov@yandex.ru> wrote:
Hi, I have written some numpy tips and tricks I am using, which may be interesting to you. This is quite long reading, so I've splitted it into two parts:
http://arogozhnikov.github.io/2015/09/29/NumpyTipsAndTricks1.html
The recommendation of inverting a permutation by argsort'ing it, while it works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time:
In [14]: import numpy as np
In [15]: arr = np.random.rand(10)
In [16]: perm = arr.argsort()
In [17]: perm Out[17]: array([5, 0, 9, 4, 2, 8, 6, 7, 1, 3])
In [18]: inv_perm = np.empty_like(perm)
In [19]: inv_perm[perm] = np.arange(len(perm))
In [20]: np.all(inv_perm == perm.argsort()) Out[20]: True
It does require two lines of code, so for small stuff it is probably good enough to argsort, but it gave e.g. np.unique a nice boost on larger arrays when we applied it there.
Jaime
http://arogozhnikov.github.io/2015/09/30/NumpyTipsAndTricks2.html
Comments are welcome, specially if you know any other ways to make this code faster (or better).
Regards, Alex.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
-- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial. _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
It will still have to a nice png, but you get an interactive figure when it is live. You just blew my mind. =D +1 to Python 3 and aliasing numpy as np.
I would suggest
%matplotlib notebook
It will still have to a nice png, but you get an interactive figure when it is live.
Amazing, thanks. I was using mpld3 for this. (for some strange reason I need to put %matplotlib notebook before each plot)
The recommendation of inverting a permutation by argsort'ing it, while it works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time: Actually, there is (later in post) a linear solution using bincount, but your code is definitely better. Thanks!
2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov <alex.rogozhnikov@yandex.ru>:
I would suggest
%matplotlib notebook
It will still have to a nice png, but you get an interactive figure when it is live.
Amazing, thanks. I was using mpld3 for this. (for some strange reason I need to put %matplotlib notebook before each plot)
You should create a figure before each plot instead of putthon %matplotlib notebook plt.figure() ....
The recommendation of inverting a permutation by argsort'ing it, while it
works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time:
Actually, there is (later in post) a linear solution using bincount, but your code is definitely better. Thanks!
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
2015-10-02 9:48 GMT+02:00 Kiko <kikocorreoso@gmail.com>:
2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov <alex.rogozhnikov@yandex.ru>:
I would suggest
%matplotlib notebook
It will still have to a nice png, but you get an interactive figure when it is live.
Amazing, thanks. I was using mpld3 for this. (for some strange reason I need to put %matplotlib notebook before each plot)
You should create a figure before each plot instead of putthon %matplotlib notebook plt.figure() ....
putthon == putting
The recommendation of inverting a permutation by argsort'ing it, while it
works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time:
Actually, there is (later in post) a linear solution using bincount, but your code is definitely better. Thanks!
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
Thanks for comments, I've fixed the named issues. Code is python2&3 compatible, I aliased numpy and used better inversion. Specially thanks for pointing at histogram equalization - I've added example for images. Probably some other 'visual' examples would help - I'll try to invent something to other points, but this is not simple. (I left %matplolib inline due to more appropriate rendering) Alex. 02.10.15 10:50, Kiko пишет:
2015-10-02 9:48 GMT+02:00 Kiko <kikocorreoso@gmail.com <mailto:kikocorreoso@gmail.com>>:
2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov <alex.rogozhnikov@yandex.ru <mailto:alex.rogozhnikov@yandex.ru>>:
I would suggest
%matplotlib notebook
It will still have to a nice png, but you get an interactive figure when it is live.
Amazing, thanks. I was using mpld3 for this. (for some strange reason I need to put %matplotlib notebook before each plot)
You should create a figure before each plot instead of putthon %matplotlib notebook plt.figure() ....
putthon == putting
The recommendation of inverting a permutation by argsort'ing it, while it works, is suboptimal, as it takes O(n log(n)) time, and you can do it in linear time:
Actually, there is (later in post) a linear solution using bincount, but your code is definitely better. Thanks!
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org> https://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (6)
-
Alex Rogozhnikov -
Jaime Fernández del Río -
Juan Nunez-Iglesias -
Kiko -
Stefan van der Walt -
Thomas Caswell