0

the Following program:

X=np.array([[1,-7,8],[6,4,9],[7,8,9]],dtype=np.int8)
Y=np.array([1,-1,1],dtype=np.int8)
w=2
sigma=20

for i in range (len(X)):
    e_i=Y-np.dot(w,X)
    Ls_w=1/len(X)*(np.sum(Y-np.dot(w,X)))**2
    delta_ls=-1/len(X)*np.sum(2*np.dot(X,e_i))
    while delta_ls>sigma:
        if(e_i != 0):
            w+=2*np.dot(e_i,X)
            print(w,e_i)

it gives me this : if(e_i != 0): ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

How to fix it ?

  • Sounds like you're supposed to use `e_i.any` or `e_i.all` – Samwise Aug 14 '22 at 20:35
  • Do you _understand_ what the error message is telling you? – John Gordon Aug 14 '22 at 20:36
  • The problem is that `if arr:` isn't implemented for numpy arrays other than length 0 or 1. How you need to replace this expression depends on what your code has to do. Read the linked duplicates for some explanations. You can also look at a dozen other ones at https://duckduckgo.com/?q=truth+value+of+an+array+ambiguous+site%3Astackoverflow.com&ia=web to grasp the underlying issue better. – Andras Deak -- Слава Україні Aug 14 '22 at 20:36

0 Answers0