Guest User

Untitled

a guest
Jun 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import numpy as np
  2.  
  3. ####################################
  4. # Comparison of the 'list'
  5. ####################################
  6.  
  7. # In case of the 'list' data,
  8. # the result of the comparison using '==' and/or '!='
  9. # is whether all the elements meet the condition.
  10. # The result is just 'True' or 'False', not elementwise.
  11.  
  12. test_data = [[1,2,3],[4,5,6]]
  13. test_data1 = [[0,2,3],[4,5,6]]
  14. actual = [[1,2,3],[4,5,6]]
  15.  
  16. print(test_data == actual)
  17. # [out] >> True
  18.  
  19. print(test_data1 == actual)
  20. # [out] >> False
  21.  
  22. ##############################################
  23. # Comparison of the numpy 'ndarray'
  24. ##############################################
  25.  
  26. # In case of the 'ndarray' data,
  27. # the result of the comparison using '==' and/or '!=' is elementwise.
  28. # If you want to check whether all the elements meet the condition,
  29. # use .all() command.
  30.  
  31. test_data = np.array([1,2,3])
  32. test_data1 = np.array([0,2,3])
  33. actual = np.array([1,2,3])
  34.  
  35. # element wise comparison
  36. print(test_data == actual)
  37. # [out] >> [True, True, True]
  38. print(test_data1 == actual)
  39. # [out] >> [False, True, True]
  40.  
  41.  
  42. # comparison of all the elements
  43. print((test_data == actual).all())
  44. # [out] >> True
  45. print((test_data1 == actual).all())
  46. # [out] >> False
Add Comment
Please, Sign In to add comment