[Numpy-discussion] use slicing as argument values?
Robert Kern
robert.kern@gmail....
Thu Jul 12 15:49:16 CDT 2012
On Thu, Jul 12, 2012 at 9:46 PM, Chao YUE <chaoyuejoy@gmail.com> wrote:
> Hi Ben,
>
> it helps a lot. I am nearly finishing a function in a way I think pythonic.
> Just one more question, I have:
>
> In [24]: b=np.arange(1,11)
>
> In [25]: b
> Out[25]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>
> In [26]: b[slice(1)]
> Out[26]: array([1])
>
> In [27]: b[slice(4)]
> Out[27]: array([1, 2, 3, 4])
>
> In [28]: b[slice(None,4)]
> Out[28]: array([1, 2, 3, 4])
>
> so slice(4) is actually slice(None,4), how can I exactly want retrieve a[4]
> using slice object?
You don't. You use 4.
--
Robert Kern
More information about the NumPy-Discussion
mailing list