title: Cleaner way to compare array values?
body: <p>I have a maze:</p>
  
  <pre><code>||||||||||||||||||||||
  | ||        | |    . |
  |    |||||| | |||||| |
  ||||||        |      |
  |    | |||||| || |||||
  | |||| |         |   |
  |        ||| |||   | |
  ||||||||||    |||||| |
  |  P       ||        |
  ||||||||||||||||||||||
  </code></pre>
  
  <p>along with the following code:</p>
  
  <pre><code>import numpy
  import copy
  import collections
  
  UP = [0,1]
  DOWN = [0,-1]
  LEFT = [-1,0]
  RIGHT = [1,0]
  
  theProblem = numpy.empty((rows,cols), dtype=object)
  
  ## code to generate the below matrix ##
  [['|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|'
    '|' '|' '|' '|']
   ['|' ' ' '|' '|' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '|' ' ' '|' ' ' ' ' ' '
    ' ' ' ' ' ' '|']
   ['|' ' ' ' ' ' ' ' ' '|' '|' '|' '|' '|' '|' ' ' '|' ' ' '|' '|' '|' '|'
    '|' '|' ' ' '|']
   ['|' '|' '|' '|' '|' '|' ' ' ' ' ' ' ' ' ' ' 'P' ' ' ' ' '|' ' ' ' ' ' '
    ' ' ' ' ' ' '|']
   ['|' ' ' ' ' ' ' ' ' '|' ' ' '|' '|' '|' '|' '|' '|' ' ' '|' '|' ' ' '|'
    '|' '|' '|' '|']
   ['|' ' ' '|' '|' '|' '|' ' ' '|' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '|'
    ' ' ' ' ' ' '|']
   ['|' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '|' '|' '|' ' ' '|' '|' '|' ' ' ' '
    ' ' '|' ' ' '|']
   ['|' '|' '|' '|' '|' '|' '|' '|' '|' '|' ' ' ' ' ' ' ' ' '|' '|' '|' '|'
    '|' '|' ' ' '|']
   ['|' '.' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '|' '|' ' ' ' ' ' ' ' ' ' '
    ' ' ' ' ' ' '|']
   ['|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|' '|'
    '|' '|' '|' '|']]
  #######################################################################
  
  # stateX = location of P[0] #
  # stateY = location of P[1] #
  print "WALL" if theProblem[stateX+DOWN[0],stateY+DOWN[1]] == '|' else "GO"
  </code></pre>
  
  <p>Is there a cleaner way to do the last line comparison? I'm pretty new to <code>numpy</code>, but it seems there has to be a more clever way to compare surrounding cells without explicitly doing like:</p>
  
  <pre><code>print "WALL" if theProblem[stateX+DOWN[0],stateY+DOWN[1]] == '|' else "GO"
  print "WALL" if theProblem[stateX+UP[0],stateY+UP[1]] == '|' else "GO"
  print "WALL" if theProblem[stateX+LEFT[0],stateY+LEFT[1]] == '|' else "GO"
  print "WALL" if theProblem[stateX+RIGHT[0],stateY+RIGHT[1]] == '|' else "GO"
  </code></pre>