Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- ####################################
- # Comparison of the 'list'
- ####################################
- # In case of the 'list' data,
- # the result of the comparison using '==' and/or '!='
- # is whether all the elements meet the condition.
- # The result is just 'True' or 'False', not elementwise.
- test_data = [[1,2,3],[4,5,6]]
- test_data1 = [[0,2,3],[4,5,6]]
- actual = [[1,2,3],[4,5,6]]
- print(test_data == actual)
- # [out] >> True
- print(test_data1 == actual)
- # [out] >> False
- ##############################################
- # Comparison of the numpy 'ndarray'
- ##############################################
- # In case of the 'ndarray' data,
- # the result of the comparison using '==' and/or '!=' is elementwise.
- # If you want to check whether all the elements meet the condition,
- # use .all() command.
- test_data = np.array([1,2,3])
- test_data1 = np.array([0,2,3])
- actual = np.array([1,2,3])
- # element wise comparison
- print(test_data == actual)
- # [out] >> [True, True, True]
- print(test_data1 == actual)
- # [out] >> [False, True, True]
- # comparison of all the elements
- print((test_data == actual).all())
- # [out] >> True
- print((test_data1 == actual).all())
- # [out] >> False
Add Comment
Please, Sign In to add comment