[Numpy-discussion] Numpy array performance issue

Bruno Santos bacmsantos at gmail.com
Thu Feb 25 08:51:38 EST 2010


I just realized that the line lsPhasedValues =
numpy.unique1d(aLoci[numpy.where(aLoci[index_nSize]>0)]) does not work
properly.
How can I get the unique values of an array based on their indexes?

2010/2/25 Bruno Santos <bacmsantos at gmail.com>

> After implementation all the possibilities we discuss yesterday mi fastest
> version is this one:
> index_nSize=numpy.arange(0,length,nSize)
> lsPhasedValues = numpy.unique1d(aLoci[numpy.where(aLoci[index_nSize]>0)])
> ...
>
> bigaLoci = (aLoci>=r)
> k = (aLoci>=r).sum()
>
>
> This is taking around 0.12s for my test cases.
> The other version you proposed:
>
> j = numpy.arange(length)
> j_nSize_mask = ((j%nSize)==0)
> lsPhasedValues = numpy.unique1d(aLoci[j_nSize_mask&aLoci>=0])
>
> bigaLoci = (aLoci>=r)
> q = (j_nSize_mask&bigaLoci).sum()
> k = bigaLoci.sum()
>
> This takes 0.75s for the same input.
>
> With this I was able to speed up my code in a afternoon more than in the
> two previous weeks. I don't have enough words to thank you.
>
> All the best,
> Bruno
>
> 2010/2/24 Robert Kern <robert.kern at gmail.com>
>
>> On Wed, Feb 24, 2010 at 12:38, Bruno Santos <bacmsantos at gmail.com> wrote:
>>
>> > This is probably me just being stupid. But what is the reason for this
>> peace
>> > of code not to be working:
>> > index_nSize=numpy.arange(0,length,nSize)
>> > lsPhasedValues = set([aLoci[i] for i in xrange(length) if (i%nSize==0
>> and
>> > aLoci[i]>0)])
>> > lsPhasedValues1 = numpy.where(aLoci[index_nSize]>0)
>>
>> Because this is not correct. where() gives you indices where the
>> argument is True; you want the values in aLoci. Chris misunderstood
>> your request.
>>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>>  -- Umberto Eco
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100225/9d404843/attachment.html>


More information about the NumPy-Discussion mailing list