2

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

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
M. Page
  • 2,694
  • 2
  • 20
  • 35

1 Answers1

1

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])
Levon
  • 10,408
  • 4
  • 47
  • 42