0

I tried to use numpy.equal on chararrays but I keep getting the future warning error. I reduced it to compare an array with itself and it still pops up. What am I doing wrong? Is this operation not allowed on this type of array?

a=np.chararray((1,4,3),itemsize=2)
a.fill('a')
np.equal (a,a)

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform the elementwise comparison

MaxS
  • 978
  • 3
  • 17
  • 34
  • any reason you're using chararrays instead of normal numpy array? docs discourage using them for new code – filippo Dec 08 '18 at 11:07
  • @ filippo : no, no particular reason. but a "normal" numpy array with strings gives the same result – MaxS Dec 08 '18 at 11:10
  • @ filippo : or is your question: Why do you use strings in your numpy array? – MaxS Dec 08 '18 at 11:12
  • 1
    `a == a` should work fine, `(a == a).all()` if you need all values to be equal – filippo Dec 08 '18 at 11:13
  • @ filippo : I want to know which values are equal. This was just a minimal example to show the problem. A real case would check np.equal (a,b). but if np.equal (a,a) doesn't even work, there is no point solving the problem at this stage – MaxS Dec 08 '18 at 11:17
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/184913/discussion-between-maxs-and-filippo). – MaxS Dec 08 '18 at 11:20
  • Possible duplicate of [Comparing two numpy arrays for equality, element-wise](https://stackoverflow.com/questions/10580676/comparing-two-numpy-arrays-for-equality-element-wise) – filippo Dec 08 '18 at 12:21

0 Answers0