The truth value of an array with more than one element is ambiguous Use a any or a all

0 votes

I couldn't figure out the problem.

here my code

from scipy.spatial.distance import euclidean

x_o = np.array([3,8,3,4,1,7,5,3,8,2,10,8,10,10,9,8,10,6,7,6])
y_o = np.array([7,3,1,6,10,10,3,6,5,10,10,9,8,2,1,3,1,1,2,2])


def m_dis_sampling(x_o, y_o, sample_size):
    sample = []
    
    
    x_value = x_o[1]
    y_value = y_o[1]
    x_o = np.delete(x_o, 1)
    y_o = np.delete(y_o, 1)
    sample.append((x_value,y_value))
    arr=np.array(sample)
    dst=[]
    a=1
   
    while a <sample_size:
        if np.logical_or(len(x_o)>0, len(y_o)>0):
            for i in range(len(x_o)):

                ekl=euclidean((x_o[i], y_o[i]),(np.mean(arr[:,0]),np.mean(arr[:,1])))
                dst += [[ekl,i]]
           
            index=(max(dst, key=lambda x: x[0]))[1]  

            x_value = x_o[index]
            y_value = y_o[index]

            x_o = np.delete(x_o, index)
            y_o = np.delete(y_o, index)
            arr = np.concatenate((arr, [[x_value, y_value]]), axis=0)
            dst=[]
           
        else: 
            a=sample_size
        a+=1
          
    return arr

and there is a control statement, when it runs 

assert maximum_distance_sampling(x_o,y_o, 10) == [(1, 10),
 (10, 1),
 (10, 10),
 (3, 1),
 (2, 10),
 (9, 1),
 (10, 2),
 (7, 10),
 (6, 1),
 (10, 8)]

I got this eror

ValueError                                Traceback (most recent call last)
<ipython-input-69-2de6e8a36886> in <module>
      3 y_o = np.array([7,3,1,6,10,10,3,6,5,10,10,9,8,2,1,3,1,1,2,2])
      4 
----> 5 assert maximum_distance_sampling(x_o,y_o, 10) == [(1, 10),
      6  (10, 1),
      7  (10, 10),

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

Thank you

Dec 17, 2020 in Python by muammer
• 120 points
7,773 views
Hey, @Muammer,

I would suggest you go through this:https://blog.finxter.com/how-to-fix-valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous-use-a-any-or-a-all/

As it is possible happening multiple ambiguities.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

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

Hello @kartik, Since different users might have different ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
23,371 views
0 votes
0 answers

Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

 I am getting this error: Truth value of ...READ MORE

May 9, 2022 in Python by Kichu
• 19,040 points
1,775 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
959 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,463 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP