Folks,

  I want to index a[j,k], clipping j or k to the edge if they're 1 off --

def aget( a, j, k ):
    """ -> a[j,k]  or a[edge] """
        # try:
        #    return a[j,k]  -- nope, -1
        # except IndexError:
    m,n = a.shape
    return a[ min(max(j, 0), m-1), min(max(k, 0), n-1)]
    

This works but is both ugly and 5* slower than plain a[j][k].
Is there a better way ?

(Sorry if this is a duplicate, must come up often.)
cheers
  -- denis

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to