1
votes

i used if else to check if the element at index i,i of a numpy matrix is 0

if a[i, i]==0:

got the error ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Is there any workaround for this?

1
This error is not from the line you showed. Provide more codeRafalS
if any(a[i, i]==0) your a[i,i] Has apparently more than 1 dimensionGrzegorz Skibinski
what's the sbape and dtype of `a?hpaulj

1 Answers

0
votes

The problem with your code is that a[i, i] is not a single value rather a list or numpy array. And you can't check with just one if condition all values in a list/numpy array.
What you could do is:

for item in a.flatten():
    if item == =.
       # do sth