I have a numpy array of Python object. I want to compare the array against a python object and I don't want the comparison with ==
operator, but just a reference comparison is enough for my requirements.
import numpy as np
a = np.array(["abc", "def"], dtype="object")
a == "abc"
I am sure about my array that reference copy is enough. Let's say all strings, I have in my array are interned.
This is primarily to improve the performance when comparing zillion values. Python object comparisons are really slow.
a is "abc" won't do what I want because
In [1]: import numpy as np
In [2]: a = np.array(["abc", "def"], dtype="object")
In [3]: a == "abc"
Out[3]: array([ True, False], dtype=bool)
In [4]: a is "abc"
Out[4]: False
I want the result of a == "abc"
but I don't Python's __eq__
method be used for the same but just the is
operator.