[Numpy-discussion] variable end border in arrays
sebastian at sipsolutions.net
Fri Jun 5 03:55:16 EDT 2015
On Fr, 2015-06-05 at 15:17 +0800, Pablo wrote:
> If I want to remove 1 element in the beginning and the end of a numpy
> array "x" we do:
> 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
> it will produce an empty array because border==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)
Yes and no. You could do if/else and use a None. Or just use the
positive index: x[border:x.shape - border].
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion