Re: [Numpy-discussion] array of matrices
Le Friday 27 March 2009 23:38:25 Bryan Cole, vous avez écrit : I have a number of arrays of shape (N,4,4). I need to perform a vectorised matrix-multiplication between pairs of them I.e. matrix-multiplication rules for the last two dimensions, usual element-wise rule for the 1st dimension (of length N). (How) is this possible with numpy? I think dot will work, though you'll need to work a little bit to get the answer: import numpy as np a = np.array([[1,2], [3,4]], np.float) aa = np.array([a,a+1,a+2]) bb = np.array((a*5, a*6, a*7, a*8)) np.dot(aa, bb).shape (3, 2, 4, 2) for i, a_ in enumerate(aa): ... for j, b_ in enumerate(bb): ... print (np.dot(a_, b_) == np.dot(aa, bb)[i,:,j,:]).all() ... True True True True True True True True True True True True -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, 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://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Quikest way to create a symetric (diagonal???) matrix ?
On Wed, Mar 26, 2008 at 09:48:02AM -0400, Pierre GM wrote: All, What's the quickest way to create a diagonal matrix ? I already have the elements above the main diagonal. Of course, I could use loops: m=5 z = numpy.arange(m*m).reshape(m,m) for k in range(m): for j in range(k+1,m): z[j,k] = z[k,j] But I was looking for something more efficient. From your code, you certainly meant symetric and not diagonal. Maybe you can speed up things a bit by assigning slices: for k in range(m): ... z[k:, k] = z[k, k:] -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, 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: Digital signature ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] argsort memory problem?
On Tue, Jan 29, 2008 at 02:58:15PM +0100, Oriol Vendrell wrote: Hi all, I've noticed something that looks like an odd behaviour in array.argsort(). # test1 - from numpy import array while True: a=array([8.0,7.0,6.0,5.0,4.0,2.0]) i=a.argsort() # --- # test2 - from numpy import array a=array([8.0,7.0,6.0,5.0,4.0,2.0]) while True: i=a.argsort() # --- test1 runs out of memory after a few minutes, it seems that in each cycle some memory is allocated and never returned back. test2 runs fine until killed. I'm unsure if I'm missing something or if this could be a bug. I'm using numpy 1.0.1 with python 2.4.4 in a debian stable system. Certainly a bug, but it has been fixed and I cannot reproduce in debian sid (using 1.0.4-5) -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, 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: Digital signature ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Scipy release
On Wed, Jul 04, 2007 at 11:59:28AM +0100, John Reid wrote: Ok I'll try that although I guess that it turns off all warnings. that It does. See the documentation of the warnings module for the full syntax and fine grained control. -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services Informatique scientifique: http://www.logilab.fr/science Reprise et maintenance de sites CPS: http://www.migration-cms.com/ signature.asc Description: Digital signature ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] PyChecker
On Tue, Mar 20, 2007 at 08:48:46PM -0600, Charles R Harris wrote: On 3/20/07, Pierre GM [EMAIL PROTECTED] wrote: On Tuesday 20 March 2007 15:29:01 Charles R Harris wrote: but I want to suggest that we run pychecker, and maybe pylint, over the python code to look for errors. I'm using Pydev w/ Eclipse that supports pylint. I usually don't have any warning from pylint about numpy. Could you be more specific ? ___ For instance, make a file warn.py containing the line: from numpy import * snip Neither is an error, but it is bad style to shadow builtins and unexpected errors can result. The second warning refers to this bit of code: If you go that way, it is bad style to import * in production code, precisely because it can lead to identifier shadowing. You should try import numpy as n Remember the zen of Python: Namespaces are one honking great idea -- let's do more of those! -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services Informatique scientifique: http://www.logilab.fr/science Reprise et maintenance de sites CPS: http://www.migration-cms.com/ signature.asc Description: Digital signature ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Unifying numpy, scipy, and matplotlib docstring formats
On Sun, Feb 25, 2007 at 06:44:37PM +0200, Jouni K. Seppänen wrote: Barry Wark [EMAIL PROTECTED] writes: Yes, I agree. I wasn't coming at so much from the goal of making Pylab a Matlab clone (as you point out, that's silly, and misses much of the advantage of Python), but rather from the goal of making interactive use as efficient as possible. When I fire up ipython -pylab to do some quick exploration, it's nice not to have to type N.blah or pylab.plot IMHO the greatest strength of Matlab in interactive use is the matrix input format. For one thing, it is easier to type something like [0 1 0; 1 0 0; 0 0 1] than array([[0,1,0],[1,0,0],[0,0,1]]) A very nice shortcut in my opinion is the one supported by the HP scientific calculators (HP28, HP48 in my days), which would look like: array([[0,1,0], 1, 0, 0, 0, 0, 1]) I'm not quite sure how this could be generalized nicely for arbitrary shapes, but for arrays of rank 2 (which are a very common case where people are actually typing the values) it feels nice (especially on a french keyboard where the square brackets are awkward to type in) -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations D�veloppement logiciel sur mesure: http://www.logilab.fr/services Informatique scientifique: http://www.logilab.fr/science Reprise et maintenance de sites CPS: http://www.migration-cms.com/ signature.asc Description: Digital signature ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion