0

Why do I receive an error for the all function in my function?

import numpy as np
A = np.matrix([[.6+1j,.5], [.6,.5]])
def isNormalcomplex(A):
    if (all(A@A.T.conj() == A.T.conj()@A)):
        print("The matrix is normal")
    else:
        print("The matrix is Non-normal")
isNormalcomplex(A)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Maybe try: `np.all` --> `np.all(A@A.T.conj() == A.T.conj()@A)` – Mark Apr 23 '21 at 21:15
  • You can try `(A@A.T.conj() == A.T.conj()@A).all()` and check [NumPy ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()](https://stackoverflow.com/questions/22175489/numpy-valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambi) – Nikolaos Chatzis Apr 23 '21 at 21:18
  • Thanks.np.all is a solution as well –  Apr 23 '21 at 21:19

0 Answers0