How to slice range of array along a (a-priori unknown) axis?
Maarten van Reeuwijk
maarten at remove_this_ws.tn.tudelft.nl
Thu Feb 5 03:02:55 EST 2004
> def el_remove_bcells(var, axis):
> if axis == 0:
> return var[1:-1]
> else:
> return eval("var[%s1:-1]" % ":," * axis)
Thanks, that does the trick! I love the fact that you can create commands at
runtime :). I also found a command called swapaxes, which is very fast, so
just in case you're interested, here's another way:
def el_remove_bcells(var, axis):
swap = swapaxes(var, 0, axis)
swap = swap[1:-1]
return swapaxes(swap, 0, axis)
--
===================================================================
Maarten van Reeuwijk Thermal and Fluids Sciences
Phd student dept. of Multiscale Physics
www.ws.tn.tudelft.nl Delft University of Technology
More information about the Python-list
mailing list