Hello,
I'm trying to find a clear and fast equivalent to the index method of
plain python list :[color=blue][color=green]
>> a = [5,1,4,3,4]
>> a.index(4)[/color][/color]
2
I have to use it on a Numeric array, so the best I've come up with is
(rather ugly I think) :[color=blue][color=green]
>> from Numeric import array, equal, nonzero
>> a = array([5,1,4,3,4])
>> nonzero(equal(a ,4))[0][/color][/color]
2
Does someone know of a more Pythonic way ?
Thanks,
I'm trying to find a clear and fast equivalent to the index method of
plain python list :[color=blue][color=green]
>> a = [5,1,4,3,4]
>> a.index(4)[/color][/color]
2
I have to use it on a Numeric array, so the best I've come up with is
(rather ugly I think) :[color=blue][color=green]
>> from Numeric import array, equal, nonzero
>> a = array([5,1,4,3,4])
>> nonzero(equal(a ,4))[0][/color][/color]
2
Does someone know of a more Pythonic way ?
Thanks,
Comment