[SciPy-user] array slice problems ...

Stef Mientki stef.mientki at gmail.com
Sun Mar 16 13:27:37 EDT 2008


thanks Alan and Sebastien,

Sebastian Stephan Berg wrote:
> Hello,
>
> maybe I am doing something wrong or misunderstood it, but with your code
> I get:
>
> a_array = [[1], [2], [3], [4]]
>   
???
> (so the second part does not actually work). While I think you want the
> array to be shaped [[1,2,3,4]]?
> But anyways, that second array can be sliced with [:,1:3] as you want
> giving you all of the first dimension and from the second dimension only
> items 1:3. So I think what you want is simply not using two seperate
> slicings. Another example:
>
> a = array([[1,2,3,4], [2,3,4,5]])
> a[:,1:3] giving array([[2,3], [3,4]])
>
>   
I din't know there was a difference between separate slices like [:][1:3] 
and a double dimension slice like [:,1:3],
thanks.
btw Alan mentioned that separate slices takes a copy (just like lists),
while I thought arrays were never copied unless you explicitly tells the 
array to do ??
> This of course does only work with arrays and not with lists.
>
>   
yes, I knew that ;-)

cheers,
Stef
> Regards,
>
> Sebastian
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>   




More information about the SciPy-User mailing list