On Fr, 2015-06-05 at 15:17 +0800, Pablo wrote: > 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) >
Yes and no. You could do if/else and use a None. Or just use the positive index: x[border[0]:x.shape[0] - border[1]]. - Sebastian > Thanks, > Pablo > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
signature.asc
Description: This is a digitally signed message part
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion