Re: [Numpy-discussion] (Late) summary of PEP-225 discussion at Scipy
One operator which could be used is '%'. We could keep the current behaviour for ARRAY%SCALAR but have ARRAY%ARRAY as being matrix multiplication. It has the same precedence as *,/. James ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] How to do: y[yT] = y+T
Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to do: y[yT] = y+T
On Mon, Oct 27, 2008 at 12:41:06PM +0100, Nicolas ROUX wrote: Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold You are close, you just need to have the right hand side also use vector indexing (since otherwise you are trying to add something of length y to a subset of y): y[y Threshold] = y[y Threshold] + Threshold Gabriel ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] [mailinglist] How to do: y[yT] = y+T
Nicolas ROUX schrieb: Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold Hi, your solution does not work, becaus the arrays on both side do not have the same size in generall. You can do it in place: y[yT] += T or explicitely (slower/more memory): y[yT] = y[yT] + T Greetings, Uwe To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- Dr. rer. nat. Uwe Schmitt FE Mathematik mineway GmbH Science Park 2 D-66123 Saarbrücken Telefon: +49 (0)681 8390 5334 Telefax: +49 (0)681 830 4376 [EMAIL PROTECTED] www.mineway.de Geschäftsführung: Dr.-Ing. Mathias Bauer Amtsgericht Saarbrücken HRB 12339 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] [mailinglist] How to do: y[yT] = y+T
On Mon, Oct 27, 2008 at 12:45:44PM +0100, Uwe Schmitt wrote: Nicolas ROUX schrieb: Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold Hi, your solution does not work, becaus the arrays on both side do not have the same size in generall. You can do it in place: y[yT] += T Nice, I didn't know this :-) Thanks. Gabriel ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to do: y[yT] = y+T
Le Monday 27 October 2008 12:41:06 Nicolas ROUX, vous avez écrit : Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold let's see : y[yT] += T Is it what you want ? To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- David DouardLOGILAB, Paris (France), +33 1 45 32 03 12 Formations Python, Zope, Debian : http://www.logilab.fr/formations Développement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science signature.asc Description: This is a digitally signed message part. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to do: y[yT] = y+T
Thanks for all of you, for this fast and good reply ;-) Nicolas. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Douard Sent: Monday, October 27, 2008 12:51 PM To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] How to do: y[yT] = y+T Le Monday 27 October 2008 12:41:06 Nicolas ROUX, vous avez écrit : Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold let's see : y[yT] += T Is it what you want ? To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- David DouardLOGILAB, Paris (France), +33 1 45 32 03 12 Formations Python, Zope, Debian : http://www.logilab.fr/formations Développement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] (Late) summary of PEP-225 discussion at Scipy
On 27-Oct-08, at 7:22 AM, James Philbin wrote: One operator which could be used is '%'. We could keep the current behaviour for ARRAY%SCALAR but have ARRAY%ARRAY as being matrix multiplication. It has the same precedence as *,/. The problem is that it would monkey with existing semantics for broadcasting, and break with all the other arithmetic operators in this regard. I can't see it ever being accepted for that reason. Example: In [514]: x Out[514]: array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) In [515]: y Out[515]: array([0, 1, 2]) In [516]: x % y Out[516]: array([[0, 0, 0], [0, 0, 1], [0, 0, 0]]) David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] How to do: y[yT] = y+T
If what you are trying to do is actually ensure all data is within the range [a,b], you may be interested to know that python's % operator works on floating-point numbers: In [1]: -0.1 % 1 Out[1]: 0.90002 So if you want all samples in the range (0,1) you can just do y%=1. Anne 2008/10/27 Nicolas ROUX [EMAIL PROTECTED]: Thanks for all of you, for this fast and good reply ;-) Nicolas. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Douard Sent: Monday, October 27, 2008 12:51 PM To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] How to do: y[yT] = y+T Le Monday 27 October 2008 12:41:06 Nicolas ROUX, vous avez écrit : Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold let's see : y[yT] += T Is it what you want ? To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- David DouardLOGILAB, Paris (France), +33 1 45 32 03 12 Formations Python, Zope, Debian : http://www.logilab.fr/formations Développement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] How to do : x[i,j] = y[k, j] with k = i+sj
Hi, Me again ;-) I have now a new question to ask (I hope not too silly). How to do : for j in range(yHeight): for i in range(xWidth): x[j,i] = y[k,i] with k = numpy.mod(i+sj,yHeight) With efficient numpy code, without the double for ? Thanks, Cheers, Nicolas. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Uwe Schmitt Sent: Monday, October 27, 2008 12:46 PM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] [mailinglist] How to do: y[yT] = y+T Nicolas ROUX schrieb: Hello, I hope this is not a silly question ;-) I have a Numpy array, and I want to process it with : if the value is lower than Threshold, then increase by Threshold I would like to translate it as: y[yTreshold] = y + Treshold Hi, your solution does not work, becaus the arrays on both side do not have the same size in generall. You can do it in place: y[yT] += T or explicitely (slower/more memory): y[yT] = y[yT] + T Greetings, Uwe To benefit from the Numpy speed. But this doesn't work, any idea ? Thanks, Cheers, Nicolas. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion -- Dr. rer. nat. Uwe Schmitt FE Mathematik mineway GmbH Science Park 2 D-66123 Saarbrücken Telefon: +49 (0)681 8390 5334 Telefax: +49 (0)681 830 4376 [EMAIL PROTECTED] www.mineway.de Geschäftsführung: Dr.-Ing. Mathias Bauer Amtsgericht Saarbrücken HRB 12339 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] any interest in including a second-order gradient?
We wrote a simple variation on the gradient() function to calculate the second derivatives. Would there be any interest in including a gradient2() in numpy? Andrew def gradient2(f, *varargs): Calculate the second-order gradient of an N-dimensional scalar function. Uses central differences on the interior and first differences on boundaries to give the same shape. Inputs: f -- An N-dimensional array giving samples of a scalar function varargs -- 0, 1, or N scalars giving the sample distances in each direction Outputs: N arrays of the same shape as f giving the derivative of f with respect to each dimension. N = len(f.shape) # number of dimensions n = len(varargs) if n == 0: dx = [1.0]*N elif n == 1: dx = [varargs[0]]*N elif n == N: dx = list(varargs) else: raise SyntaxError, invalid number of arguments # use central differences on interior and first differences on endpoints outvals = [] # create slice objects --- initially all are [:, :, ..., :] slice1 = [slice(None)]*N slice2 = [slice(None)]*N slice3 = [slice(None)]*N otype = f.dtype.char if otype not in ['f', 'd', 'F', 'D']: otype = 'd' for axis in range(N): # select out appropriate parts for this dimension out = zeros(f.shape, f.dtype.char) slice1[axis] = slice(1, -1) slice2[axis] = slice(2, None) slice3[axis] = slice(None, -2) # 1D equivalent -- out[1:-1] = (f[2:] - 2*f[1:-1] + f[:-2]) out[slice1] = (f[slice2] - 2*f[slice1] + f[slice3]) slice1[axis] = 0 slice2[axis] = 1 slice3[axis] = 2 # 1D equivalent -- out[0] = (f[2] - 2*f[1] + f[0]) out[slice1] = (f[slice3] - 2*f[slice2] + f[slice1]) slice1[axis] = -1 slice2[axis] = -2 slice3[axis] = -3 # 1D equivalent -- out[-1] = (f[-1] - 2*f{-2] + f[-3]) out[slice1] = (f[slice1] - 2*f[slice2] + f[slice3]) # divide by the squared step size outvals.append(out / dx[axis] / dx[axis]) # reset the slice object in this dimension to : slice1[axis] = slice(None) slice2[axis] = slice(None) slice3[axis] = slice(None) if N == 1: return outvals[0] else: return outvals ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] (Late) summary of PEP-225 discussion at Scipy
James Philbin wrote: One operator which could be used is '%'. We could keep the current behaviour for ARRAY%SCALAR but have ARRAY%ARRAY as being matrix multiplication. It has the same precedence as *,/. No, having completely unrelated meanings for the same operator symbol sounds like a recipe for chaos. The whole point is to make the code more readable, not less. Eric ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] (Late) summary of PEP-225 discussion at Scipy
On Mon, Oct 27, 2008 at 11:31 AM, Eric Firing [EMAIL PROTECTED] wrote: James Philbin wrote: One operator which could be used is '%'. We could keep the current behaviour for ARRAY%SCALAR but have ARRAY%ARRAY as being matrix multiplication. It has the same precedence as *,/. No, having completely unrelated meanings for the same operator symbol sounds like a recipe for chaos. The whole point is to make the code more readable, not less. Big -1 from me on this one too, for the same reasons Eric states. I just got back from some travel and will try to update the doc later this evening with all the feedback and will post again, so that we can converge on a final doc, which I'll then pitch over the fence to the python-dev list. Thanks to all who have written, and keep it coming! Cheers, f ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] ParallelProgramming wiki page
Hi, I made some changes to the ParallelProgramming wiki page to outline use of the (multi)processing module as well as the threading module. I'm very much not an expert on this - just researched it for myself, so please feel free to correct/ extend/ delete as appropriate. Robin ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] problems multiplying poly1d with number from array
Hello list - I can multiply a poly1d instance with a number, but when I multiply with a number from an array, the order matters. That seems a bug: a = array([2]) p = poly1d([1,2]) print 2*p # Works 2 x + 4 print a[0]*p # Doesn't work, returns an array [2 4] print p*a[0] # Works 2 x + 4 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ParallelProgramming wiki page
On Monday 27 October 2008 12:56:56 Robin wrote: Hi, I made some changes to the ParallelProgramming wiki page to outline use of the (multi)processing module as well as the threading module. I'm very much not an expert on this - just researched it for myself, so please feel free to correct/ extend/ delete as appropriate. I would mention the backport of multiprocessing for python-2.{4,5}: http://code.google.com/p/python-multiprocessing so the amount of editing when one switches from 2.{4,5} to 2.6 is minimal :) cheers, sebastien. -- ### # Dr. Sebastien Binet # Lawrence Berkeley National Lab. # 1 Cyclotron Road # Berkeley, CA 94720 ### signature.asc Description: This is a digitally signed message part. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ParallelProgramming wiki page
On Mon, Oct 27, 2008 at 15:20, Sebastien Binet [EMAIL PROTECTED] wrote: On Monday 27 October 2008 12:56:56 Robin wrote: Hi, I made some changes to the ParallelProgramming wiki page to outline use of the (multi)processing module as well as the threading module. I'm very much not an expert on this - just researched it for myself, so please feel free to correct/ extend/ delete as appropriate. I would mention the backport of multiprocessing for python-2.{4,5}: http://code.google.com/p/python-multiprocessing so the amount of editing when one switches from 2.{4,5} to 2.6 is minimal :) Go for it. The wiki is open to editing. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy array change notifier?
On Monday 27 October 2008 16:54:09 Erik Tollerud wrote: Is there any straightforward way of notifying on change of a numpy array that leaves the numpy arrays still efficient? Erik, may be you could try the trick presented here : http://www.scipy.org/Subclasses in the __array_wrap__ section. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy array change notifier?
On Mon, Oct 27, 2008 at 1:56 PM, Robert Kern [EMAIL PROTECTED] wrote: On Mon, Oct 27, 2008 at 15:54, Erik Tollerud [EMAIL PROTECTED] wrote: Is there any straightforward way of notifying on change of a numpy array that leaves the numpy arrays still efficient? Not currently, no. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion out of curiosity, would something like this affect efficiency (and/or work): class Notify(numpy.ndarray): def __setitem__(self, *args): self.notify(*args) return super(Notify, self).__setitem__(*args) def notify(self, *args): print 'notify:', args with also overriding setslice? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ParallelProgramming wiki page
Did you mean this one http://www.netlib.org/scalapack/pblas_qref.html ? As for the ParallelProgramming wiki page, there are some words in section Use parallel primitives about numpy.dot still I can't understand from the section: if I get numpy from sources and compile it (via python setup.py build) in my AMD X2, will numpy.dot use 2nd CPU or not? Regards, D. Frédéric Bastien wrote: Hi, Their exist open source version of parallel BLAS library. I modified the section Use parallel primitives to tell it. But my English is bad, so if someone can check it, it would be nice. Fred On Mon, Oct 27, 2008 at 4:24 PM, Robert Kern [EMAIL PROTECTED] wrote: On Mon, Oct 27, 2008 at 15:20, Sebastien Binet [EMAIL PROTECTED] wrote: On Monday 27 October 2008 12:56:56 Robin wrote: Hi, I made some changes to the ParallelProgramming wiki page to outline use of the (multi)processing module as well as the threading module. I'm very much not an expert on this - just researched it for myself, so please feel free to correct/ extend/ delete as appropriate. I would mention the backport of multiprocessing for python-2.{4,5}: http://code.google.com/p/python-multiprocessing so the amount of editing when one switches from 2.{4,5} to 2.6 is minimal :) Go for it. The wiki is open to editing. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] ParallelProgramming wiki page
On Mon, Oct 27, 2008 at 9:17 PM, dmitrey [EMAIL PROTECTED] wrote: As for the ParallelProgramming wiki page, there are some words in section Use parallel primitives about numpy.dot still I can't understand from the section: if I get numpy from sources and compile it (via python setup.py build) in my AMD X2, will numpy.dot use 2nd CPU or not? Not unless you build numpy against a paralell enabled BLAS, for example Intel MKL, ATLAS etc. I think if you compile ATLAS with threading enabled, and then build numpy using the appropriate ptlapack libraries (I forget the exact name) then the dot should use the second CPU. As Frederic added to the wiki - the number of threads to use can only be provided to atlas at compile time. With MKL I think you can choose this at run time (I think through an environment variable but I'm not sure). Similarly with the GOTO blas, but I'm not sure if numpy builds with that, so maybe we should take that reference out. Robin ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] numpy array change notifier?
Brent Pedersen wrote: On Mon, Oct 27, 2008 at 1:56 PM, Robert Kern [EMAIL PROTECTED] wrote: On Mon, Oct 27, 2008 at 15:54, Erik Tollerud [EMAIL PROTECTED] wrote: Is there any straightforward way of notifying on change of a numpy array that leaves the numpy arrays still efficient? Not currently, no. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion out of curiosity, would something like this affect efficiency (and/or work): class Notify(numpy.ndarray): def __setitem__(self, *args): self.notify(*args) return super(Notify, self).__setitem__(*args) def notify(self, *args): print 'notify:', args with also overriding setslice? I haven't given this much thought, but you'd also likely need to do this for the infix operators (+=, etc.). Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion