# [EN] ulab EP 6 compare

compare

The compare submodule is used to compare 1D and 2D arrays to find similarities, differences, choose a larger one or smaller one. The four functions have the following usage patterns:

1. result = ulab.comapre.clip( M, a, b ) It changes the value of every element less than a to a, and any element greater than b is changed to b just like maximum( a, minimum( M, b ) )
2. result = ulab.comapre.clip( M, N, b ) If M and N have the same members, the operation compares the values of M with N. If any of the elements of M is less than N, the value of N is chosen, and if any value is greater than b, the value of b is chosen instead.
3. result = ulab.compare.equal( M, N ) Comparing M and N, return True, if it is the same otherwise return False.
4. result = ulab.compare.not_equal( M, N ) Comparing M and N, return True if they are different otherwise return False.
5. result = ulab.comapre.maximum( M, N ) Compares M with N. If any element of both arrays is greater then it will be picked as a result of that sequence.
6. result = ulab.comapre.minimum( M, N ) Compares M with N. If any element of an array is smaller, it will be selected as the value of the newly created array.

Example Code

Example code18-13 creates M and N int8 type arrays of 12, then compares that each member is the same, different or not. After that, find a lesser and greater array by comparing M and N. Finally, clip the data. The result is as shown in Figure 1.

``````# code18-13
import ulab as np

M = np.array(range(12), dtype=np.int8)
N = np.linspace(12,1,12,dtype=np.int8)

print("M == N ? {}".format(np.compare.equal(M, N)))
print("M != N ? {}".format(np.compare.not_equal(M, N)))
print("minimum(M,N) = {}".format(np.compare.minimum(M,N)))
print("maximum(M,N) = {}".format(np.compare.maximum(M,N)))
print("clip(M,5,10) = {}".format(np.compare.clip(M,5,10)))
print("clip(M,N,10) = {}".format(np.compare.clip(M,N,10)))

``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.826221,"math_prob":0.9962815,"size":2895,"snap":"2023-40-2023-50","text_gpt3_token_len":728,"char_repetition_ratio":0.13386372,"word_repetition_ratio":0.06029106,"special_character_ratio":0.265285,"punctuation_ratio":0.1751938,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9986335,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-09T15:29:49Z\",\"WARC-Record-ID\":\"<urn:uuid:fbdc5fc3-09f9-4759-b1c3-1d52508c02e2>\",\"Content-Length\":\"44705\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:594b9eae-b89f-4c73-b387-329e56136209>\",\"WARC-Concurrent-To\":\"<urn:uuid:0b3efd3c-d96a-45a5-98f3-3b713750be5c>\",\"WARC-IP-Address\":\"104.21.83.161\",\"WARC-Target-URI\":\"https://www.jarutex.com/index.php/2021/08/19/5357/\",\"WARC-Payload-Digest\":\"sha1:5JEO5PVWL5NYDIP4NLHTSZ4E7AEPAMLJ\",\"WARC-Block-Digest\":\"sha1:SPN4IX5F5KGOPO6ZBOFJ5KSYNJP4YZZW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100912.91_warc_CC-MAIN-20231209134916-20231209164916-00234.warc.gz\"}"}