[Numpy-discussion] advanced indexing question

David Kershaw dskgair at gmail.com
Wed Feb 4 04:15:49 EST 2015


Sebastian Berg <sebastian <at> sipsolutions.net> writes:
> 
> Python has a mechanism both for getting an item and for setting an item.
> The latter will end up doing this (python already does this for us):
> x[:,d,:,d] = x[:,d,:,d] + 1
> so there is an item assignment going on (__setitem__ not __getitem__)
> 
> - Sebastian
> 
> 
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 

Thanks for the prompt help Sebastian,

So can I use any legitimate ndarray indexing selection object, obj, in
 x.__setitem__(obj,y)
and as long as y's shape can be broadcast to x[obj]'s shape it will always 
set the appropriate elements of x to the corresponding elements of y?






More information about the NumPy-Discussion mailing list