[Numpy-discussion] Get the index of a comparison of two lists

FRENK Andreas Andreas.FRENK@3ds....
Fri Feb 11 08:01:08 CST 2011


Hi,

I need to create a construct that returns the index of entries of the first list, if values in the first and second list are equal.

Take
valA = [1,2,3,4,20,21,22,23,24]
valB = [1,2,3,4,  5,21,22,23]
The correct solution is: [0,1,2,3,5,6,7]

A potential loop can be:
takeList=[]
for j,a in enumerate(valA):
    if a in valB:
        takeList.append(j)


Please note, valA can have entries like [1,10000000,1000000001,.....], i.e. it can be very sparse.
I also thought about using bincount, but due to the sparse nature the return values from bincount would allocate too much memory.

Any idea how to do it fast using numpy?

Thanks,
Andreas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110211/cca0edba/attachment.html 


More information about the NumPy-Discussion mailing list