[Numpy-discussion] Numpy array performance issue

Robert Kern robert.kern@gmail....
Thu Feb 25 10:25:36 CST 2010

On Thu, Feb 25, 2010 at 10:20, Bruno Santos <bacmsantos@gmail.com> wrote:
> This is the same example we discuss yesterday.

I think I can help you this time, but when we ask for complete code,
we mean complete, self-contained code that we can run immediately, not
a fragment of code that needs variables to be initialized. We also ask
for the result that you get, so you should copy-and-paste the exact
result from running that code and also show us the result that you
were expecting.

> The working code is this one:
> lsPhasedValues = [aLoci[i] for i in xrange(length) if i%21==0 and
> aLoci[i]>0]
> I was able to get the same result after a while:
> aAux =aLoci[index_nSize]
> lsPhasedValues = numpy.unique1d(aAux[numpy.where(aAux>0)[0]])
> I couldn't came up with a better solution.

You don't need the where().

  lsPhasedValues = numpy.unique1d(aAux[aAux > 0])

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

More information about the NumPy-Discussion mailing list