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 The issue is to put enough ":" before the index value inside the square bracket of the assignement. Thanks, C.
On Wed, Nov 12, 2008 at 09:43:34AM -0800, 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
The issue is to put enough ":" before the index value inside the square bracket of the assignement.
Make some slice objects! def setval(array, index, value, axis=0): key = [slice(None)]*len(array.shape) key[axis] = index array[key] = value Gabriel
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 -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma
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!
On Wed, Nov 12, 2008 at 4:36 PM, Gabriel Gellner
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?
Nope this one wouldn't have worked for me, it's basically axis=-1 but there might be additional dimensions after index C. On Nov 12, 2008, at 10:43 AM, Roberto De Almeida wrote:
On Wed, Nov 12, 2008 at 4:36 PM, Gabriel Gellner
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? _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http:// projects.scipy.org/mailman/listinfo/numpy-discussion
Thx! On Nov 12, 2008, at 10:36 AM, Gabriel Gellner 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! _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http:// projects.scipy.org/mailman/listinfo/numpy-discussion
participants (4)
-
Charles سمير Doutriaux
-
Gabriel Gellner
-
Roberto De Almeida
-
Ryan May