[Numpy-discussion] slices vs. range() over a certain axis

David Warde-Farley dwf@cs.toronto....
Fri Nov 14 22:40:33 CST 2008

I'm trying to clarify my understanding of how slicing works and how it  
differs from specifying a sequence of indices. My question is best  
illustrated by an example:

	In [278]: x = zeros((5,50))

	In [279]: y = random_integers(5,size=50)-1

The behaviour that I want is produced by:

	In [280]: x[y,range(50)] = 1

Why doesn't
	In [281]: x[y,0:50] = 1

produce the same effect? Is there a way to do what I am attempting in  
[280] with slicing?



More information about the Numpy-discussion mailing list