Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comparing
#1
I have two 2d numpy arrays to compare. How can I compare them? Eg. [[1 1] [1 2] [2 1] [2 2]] with [[1. 2.] [2. 1.] [2. 1.] [1. 2.]]. Answer should be they do not match. But if second was [[1 1] [2 1] [1 2] [2 2]] then program should say they match. (It's important that all sequences are there, but in different order).
Reply
#2
what have you tried so far?
Reply
#3
== is false because they are two different data types. you need to do type conversion. or simply go back in the program and see if you are able to use integers instead of floats whatever it is you are doing. maybe you used *1.0 or / and you got 1.0, 2,0 etc... as result? you can do

int()
//
*2 not *2.0
math.floor()

many ways to do the type conversion to integer or prevent accidentally turning all your int() to float() by using the wrong formula earlier in the program.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020