[Numpy-discussion] setting element

Roberto De Almeida roberto@dealmeida....
Wed Nov 12 12:43:22 CST 2008


On Wed, Nov 12, 2008 at 4:36 PM, Gabriel Gellner <ggellner@uoguelph.ca>wrote:

> On Wed, Nov 12, 2008 at 12:34:51PM -0600, Ryan May wrote:
> > Charles سمير Doutriaux wrote:
> > > Hello,
> > >
> > > I'm wondering if there's aquick way to do the following:
> > >
> > > s[:,5]=value
> > >
> > > in a "general" function
> > > def setval(array,index,value,axis=0):
> > >     ## code here
> >
> > Assuming that axis specifies where the index goes, that would be:
> >
> > def setval(array, index, value, axis=0):
> >       slices = [slice(None)] * len(array.shape)
> >       slices[axis] = index
> >       array[slices] = value
> >
> > (Adapted from the code for numpy.diff)
> >
> > Ryan
> >
> Jinx!
>

Shouldn't

  s[...,index] = value

work too?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081112/04954266/attachment.html 


More information about the Numpy-discussion mailing list