On Wed, Feb 3, 2010 at 9:33 PM, <markus.proel...@ifm.com> wrote: > > >> On Wed, Feb 3, 2010 at 8:43 PM, <markus.proel...@ifm.com> wrote: > >> > >> Hello, > >> > >> the following operation seems strange to me > >> > >> >>> np.left_shift(2,-1) > >> 0 > >> > >> I would have expected a right_shift by one. > > > > I wouldn't expect anything, the behavior is simply not defined. > > But it would prevent a statement like > > if x2 > 0 then > ... > else > ... > > Right now I think the left_shift ufunc calls the Python C API, so it just does the same as Python. Which seems like the right thing to do.
If you want a bit_shift function which is a combination of left and right shift, this is straightforward to do right? Something like: In [42]: x2 Out[42]: array([-2, -1, 0, 1, 2]) In [43]: def bit_shift(x1, x2): return np.choose(x2>0, [np.right_shift(x1, -x2), np.left_shift(x1, x2)]) ....: In [45]: bit_shift(2, x2) Out[45]: array([0, 1, 2, 4, 8]) Cheers, Ralf
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion