One can use numpy
's extract
function to match an element in an array. The following code matches an element 'a.'
exactly in an array. Suppose I want
to match all elements containing '.'
, how would I do that? Note that in this case, there would be two matches. I'd also like to get the row and column number of the matches. The method doesn't have to use extract
; any method will do. Thanks.
In [110]: x = np.array([['a.','cd'],['ef','g.']])
In [111]: 'a.' == x
Out[111]:
array([[ True, False],
[False, False]], dtype=bool)
In [112]: np.extract('a.' == x, x)
Out[112]:
array(['a.'],
dtype='|S2')