recipes.regexfind

recipes.regexfind(arr, expr)[source]

Find regular expression in a NumPy array

Parameters:

arr : NumPy 1darray

Array of strings to search

expr : str

Regular expression to search for in the components of arr

Returns:

ind : NumPy 1darray

Index array of elements in arr that contain expression expr. If expr was not found anywhere in arr an empty array is returned

See also

None

Examples

Suppose the array arr is given by

>>> arr
array(['L_a', 'L_b', 'R_a', 'R_b'], 
  dtype='|S3')

If we want to find all elements of arr starting with l_ or L_ we could use

>>> regexfind(arr,"[Ll]_*")
array([0, 1])