0

I am making a text based game and numpy comes back with the error

   File "maingame.py", line 60, in <module>
    if arr[character] == 20:
ValueError: The truth value of an array with more than one element is ambiguous. Use      a.any() or a.all()

if I use either of the two suggestions it says

  File "maingame.py", line 60, in <module>
    if arr[character] == arr.all(20):
  File "/usr/lib/python2.7/dist-packages/numpy/core/_methods.py", line 37, in _all
    keepdims=keepdims)
ValueError: 'axis' entry is out of bounds

my array is 56 x 43

I've already tried to expand the boundaries of the array

thanks

new error:

  File "maingame.py", line 70, in <module>
    caracterx = charaxterx - 1
NameError: name 'charaxterx' is not defined

my code:

characterx = 0
charactery = 0
character = [charactery,characterx]
if np.all(arr[character] == 20):
    print "You are is a plain. You can see far in the distance all around you"
if np.all(arr[character] == 20):
    print "You are in a city. There are tall buildings all around you. It appears to be abandoned"
if np.all(arr[character] == 20):
    print "You are in a sparse forest. It is loosely wooded."
if np.all(arr[character] == 20):
   print "You are in a dense forest. You can only see a couple meters in each direction"

1 Answer 1

2

If you are trying to check whether all elements of arr[character] equal 20, write:

if numpy.all(arr[character] == 20):

The arr[character] == 20 returns a boolean array, and numpy.all() checks that all elements of that array are true.

Sign up to request clarification or add additional context in comments.

2 Comments

the original problem is resolved but now it returns a new error, I added it to the original question
@Sudoadmin: If it's a new problem, please post a separate question. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.