[Numpy-discussion] numpy.left_shift with negative x2
Ralf Gommers
ralf.gommers@googlemail....
Wed Feb 3 06:58:49 CST 2010
On Wed, Feb 3, 2010 at 8:43 PM, <markus.proeller@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. Python
returns an error:
In [17]: 2 << -1
---------------------------------------------------------------------------
ValueError
....
>
> The documentation on
>
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.left_shift.html#numpy.left_shift
> also says that the operation is equivalent to multiplying x1 by 2**x2.
> That's not the case!
>
The line before that says "Bits are shifted to the left by appending `x2` 0s
at the right of `x1`." What does it mean to append a negative number of
zeros?
The docs could explicitly mention that x2 has to be non-negative, if that
would make it clearer.
Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100203/d669680e/attachment.html
More information about the NumPy-Discussion
mailing list