python - Determine indices of entries in an array that start with a certain string -


how can determine indices of elements in numpy array start string (e.g. using startswith)?

example

array:

test1234 testworld hello mynewcar test5678 

now need indices value starts test. desired outcome is:

[0,1,4] 

@divakar's answer way go, alternative, can use list comprehension:

a = np.array(['test1234', 'testworld', 'hello', 'mynewcar', 'test5678'])  [i i, si in enumerate(a) if si.startswith('test')] 

will give

[0, 1, 4] 

this list convert numpy array:

np.array([i i, si in enumerate(a) if si.startswith('test')]) 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -