Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 31st, 2012, 06:06 AM
amanc amanc is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 amanc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m
Reputation Power: 0
ValueError: The truth value of an array with more than one element is ambiguous.

Hello, so I have a function:

Code:
disks = array([[ 0.31730234,  0.73662906],
   [ 0.54488759,  0.09462212],
   [ 0.07500703,  0.36148366],
   [ 0.33200281,  0.04550565],
   [ 0.3420866 ,  0.9425797 ],
   [ 0.36115391,  0.16670599],
   [ 0.95586938,  0.52599398],
   [ 0.13707665,  0.6574444 ],
   [ 0.77766138,  0.56875582],
   [ 0.79618595,  0.7139309 ]])

def overlap(d1,d2,r): #d1 is disk 1, d2 is disk 2 in array
    distance = ((d1[0]-d2[0])**2 + (d1[1]-d2[1])**2)**0.5
    if distance < 2*r:
        return True
    else:
        return False

def touch_left_wall(d1,r):
    if d1[0] - r <= 0:
        return True
    else:
        return False

for d1 in disks:
    for d2 in disks:
        if overlap(d1,d2,r):
            if touch_left_wall(d1,r):
                clusters.append([d1,d2,True,False])

A cluster is that array: [float, float, boolean, boolean]

I have another function:
Code:
def joincluster(c1,c2):
if any(x in c1 for x in c2):
    c1 = c1 + c2


Where c1 and c2 are clusters. For some reason, everytime I try and run this I get this error:

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

Anyone know why? I've tried a lot of things, like making the numpy arrays lists and such but nothing is working.

Reply With Quote
  #2  
Old December 31st, 2012, 07:49 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,361 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 11 sec
Reputation Power: 383
Please post sufficient information to duplicate the problem.

"A cluster is that array: [float, float, boolean, boolean]"

array.array does not store mixed type.
numpy.array does not store mixed type.

You've done (equivalently)

from numpy import *

Code:
>>> from numpy import *
>>> A=[pi,exp(1),True,False]  # float, float, Boolean, Boolean
>>> any(x in A for x in A)
True
>>> 


I'd compute distance like this:
>>> A=disks[0]-disks[1]
>>> A.dot(A)
0.46396795702572596
>>> sqrt(A.dot(A))
0.68115193387799022

(Whereas you wrote out the indexes. Why bother with numpy if you subvert it?)


I find "if true return true else return false" repulsive.
Code:
def overlap(d1,d2,r): #d1 is disk 1, d2 is disk 2 in array
    v = d1[0]-d2[0]
    return v.dot(v) < 4*r*r

def touch_left_wall(d1,r):
    return d1[0] <= r
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > ValueError: The truth value of an array with more than one element is ambiguous.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap