[Numpy-discussion] variable end border in arrays

Pablo pnavarre at gmail.com
Fri Jun 5 03:17:13 EDT 2015


Hi,
If I want to remove 1 element in the beginning and the end of a numpy 
array "x" we do:

x[1:-1]

Now, if we have a border variable, and borders are allowed to be zero 
(which means no border), numpy syntax is inconvenient. For example if 
border=numpy.asarray([1,0]) and we try

x[border[0],-border[1]]

it will produce an empty array because border[1]==0 is not considered 
respect to the end of the array anymore.
Is it possible to solve this without if/else's ? (I work with images and 
tensor's so if/else's have too many possible combinations)

Thanks,
Pablo



More information about the NumPy-Discussion mailing list