numpy array is determined whether a character string containing substrings

  Internet to find a large circle did not find, there are a lot wrong ...

numpy.char.count(a, sub, start=0, end=None)

  This function is used to count how many times in a sub appearance, we slightly modified we can achieve what we want.

numpy.char.count(a, sub, start=0, end=None) != 0

  Specific function description see the official documents .

For example:

import numpy as np
a = np.array(['abc', 'akjs', '23ha', 'sdfg', 'arge', '8908d', 'aaaab', 'hhdaa', 'wer'], dtype='str')
np.char.count(a, 'a')
# array([1, 1, 1, 0, 1, 0, 4, 2, 0])
np.char.count(a, 'a') != 0
# array([ True,  True,  True, False,  True, False,  True,  True, False])

Guess you like

Origin www.cnblogs.com/cloud--/p/12283608.html