from numpy import array
import fnmatch
a = array(['zzzz', 'zzzd', 'zzdd', 'zddd', 'dddn', 'ddnz', 'dnzn', 'nznz',
    'znzn', 'nznd', 'zndd', 'nddd', 'ddnn', 'dnnn', 'nnnz', 'nnzn', 'nznn',
    'znnn', 'nnnn', 'nnnd', 'nndd', 'dddz', 'ddzn', 'dznn', 'znnz', 'nnzz',
    'nzzz', 'zzzn', 'zznn', 'dddd', 'dnnd'], dtype=object)

def func(ar, pattern):
    indices = [i for i, x in enumerate(ar) if fnmatch.fnmatch(x, pattern)]
return ar.take(indices)
print(func(a, '??dd'))
Search for a pattern in numpy array