On Fri, Aug 28, 2009 at 09:14, denis bzowy<denis-bz...@t-online.de> wrote: > 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 ?
Nope. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion