Finding entries containing a substring in a numpy array?
问题 I tried to find entries in an Array containing a substring with np.where and an in condition: import numpy as np foo = "aa" bar = np.array(["aaa", "aab", "aca"]) np.where(foo in bar) this only returns an empty Array. Why is that so? And is there a good alternative solution? 回答1: We can use np.core.defchararray.find to find the position of foo string in each element of bar , which would return -1 if not found. Thus, it could be used to detect whether foo is present in each element or not by