Matrix:distinct and non-distinct elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Diacono
    New Member
    • Aug 2022
    • 1

    Matrix:distinct and non-distinct elements

    Consider an M array, write a unique (M) function that returns True if the array has all distinct elements and False otherwise:
    [[1,2], [3,4]] -> True
    [[2,2], [3,4]] -> False
    my code is:

    def unique(M):
    r=len(M)
    c=len(M[0])
    check = True

    for i in range(r):
    for j in range(c):
    if M[i][j]!=M[j][i]:
    return False
    return True


    the problem is that it does not go back to the distinct elements, could someone help me to solve this error.
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Post the code using tags and indentation. What is the logic? What's with the comparison of [i][j] and [j][i] elements? Why would you return based on a not equal condition check?

    Comment

    Working...