![](https://secure.gravatar.com/avatar/cd71bb17a5ef04a06383cdcde1f370ad.jpg?s=120&d=mm&r=g)
On 07/12/2012 04:46 PM, Chao YUE 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?
thanks again!
Chao
slice is a build in python function and the online docs explain its use (http://docs.python.org/library/functions.html#slice). b[slice(4,5)] will give you something close to b[4], but not quite the same. In [8]: b[4] Out[8]: 5 In [9]: b[slice(4,5)] Out[9]: array([5]) - Jonathan Helmus