First, when doing linear algebra it is better to use matrices than arrays, as matrix was developed for such operations. This will also get you away from having to specify dot() since

- Code: Select all
`all(A*A==dot(A,A)) = True # When A is matrix`

all(A*A==dot(A,A)) = False # When A is array

Second, your line

- Code: Select all
`if np.dot(np.triu(A),np.triu(A) - np.identity(2) <= closer_I:`

is missing a closing parenthesis, which was probably just a typo on the forum, but make sure it is correct in your code.

Third (possibly related to my second comment), the error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()" is probably due to your line:

- Code: Select all
`if np.dot(np.triu(A),np.triu(A) - np.identity(2) <= closer_I:`

Here, you are asking if the dot operation is less than another array, but numpy is confused because there are multiple elements in each array you are comparing. If you want to see if ALL elements are less than closer_I, you should do something like this:

- Code: Select all
`if np.all( np.dot( np.triu(A),np.triu(A) - np.identity(2) ) <= closer_I ):`

This will return True only if all dot-product values are less than closer_I.

Fourth, I am guessing that you gave your arrays shape [2,2] for example purposes, but I want to make sure. If you really do want A to be shape [2,2] then all( triu(A)==A ) = True. You probably already know that, but better to be sure and save an exercise in futility.