Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-06 Thread Alex Rogozhnikov

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 >:




2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov
>:

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





___
NumPy-Discussion mailing list
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


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-02 Thread Alex Rogozhnikov

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!

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-02 Thread Kiko
2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov :

> 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
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-02 Thread Kiko
2015-10-02 9:48 GMT+02:00 Kiko :

>
>
> 2015-10-02 9:38 GMT+02:00 Alex Rogozhnikov :
>
>> 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
>>
>
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-01 Thread Alex Rogozhnikov
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.

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-01 Thread Stefan van der Walt
On 2015-10-01 11:46:59, Alex Rogozhnikov 
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
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-01 Thread Jaime Fernández del Río
On Thu, Oct 1, 2015 at 11:46 AM, Alex Rogozhnikov <
alex.rogozhni...@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


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-01 Thread Juan Nunez-Iglesias
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.___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Fwd: Numpy for data manipulation

2015-10-01 Thread Thomas Caswell
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 
wrote:

> On Thu, Oct 1, 2015 at 11:46 AM, Alex Rogozhnikov <
> alex.rogozhni...@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
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion