pythonnumpynumexpr

Usage of numexpr contains() function


I want to check if each element of a Numpy string array contains a given string using numexpr (2.7). I have written:

x = np.array(['abc', 'cde'])
ne.evaluate("contains(x, 'a')")

I get: ValueError: unknown type str96

I also tried to specify a dtype for x with the same result


Solution

  • This is a known issue. Try instead

    import numpy as np
    import numexpr as ne
    
    x = np.array([b'abc', b'cde'])
    ne.evaluate("contains(x, b'a')")
    # array([ True, False])