[Numpy-discussion] Finding the same value in List

Happyman bahtiyor_zohidov@mail...
Wed Apr 17 02:44:12 CDT 2013


 Hello,

I have had encountered some problem while I was trying to create the following code which finds number of the same values  and indexes in an array or list. Here is the code:

y = [ 1, 12,  3,  3,  5,  1,  1, 34, 0, 0,  1,  5]
OR 
y = array( [ 1, 12,  3,  3,  5,  1,  1, 34, 0, 0,  1,  5 ] )

b = [ [ item for item in range( len(y) ) if y[ item ] == y[ j ] ]  for j in range(0, len( y ) ) ]

answer:
   [ [ 0, 5, 6, 10], [1], [2, 3], [2, 3], [4, 11], [0, 5, 6, 10], [0, 5, 6, 10], [7], [8, 9], [8, 9], [0, 5, 6, 10], [4, 11] ]

The result I want to get is ,not that shown above as an answer, that I want to calculate the number of the same values and their indexes in not repeated way as well. For example,
'1' - 4, index: '0, 5, 6, 10'
'12' - 1, index: '1'
'3' - 2, index: '2, 3'
'5' - 2, index: '4, 11'
'34' - 1, index: '7'
'0' - 2, index: '8, 9'

Any answer would be appreciated..





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


More information about the NumPy-Discussion mailing list