From: Nils W. <nw...@is...> - 2001-07-18 12:09:04
|
Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils |
From: Paul F. D. <pa...@pf...> - 2001-07-18 14:49:57
|
Using the outer product you get a matrix that has the right size and contents but it is m*n by p*q Was that a misprint in your post? >>> x array([1, 2, 3, 4, 5, 6]) >>> x.shape=(3,2) >>> y = 10*transpose(x) >>> y array([[10, 30, 50], [20, 40, 60]]) >>> z = outerproduct(x.flat, y.flat) >>> z array([[ 10, 30, 50, 20, 40, 60], [ 20, 60, 100, 40, 80, 120], [ 30, 90, 150, 60, 120, 180], [ 40, 120, 200, 80, 160, 240], [ 50, 150, 250, 100, 200, 300], [ 60, 180, 300, 120, 240, 360]]) >>> -----Original Message----- From: num...@li... [mailto:num...@li...]On Behalf Of Nils Wagner Sent: Wednesday, July 18, 2001 4:10 AM To: num...@li... Subject: [Numpy-discussion] Kronecker product Hi, I would appreciate it, if Numpy could handle the Kronecker-product of two matrices X, Y. kron(X,Y) is the Kronecker tensor product of X and Y. The result is a large matrix formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. Nils _______________________________________________ Numpy-discussion mailing list Num...@li... http://lists.sourceforge.net/lists/listinfo/numpy-discussion |
From: Nils W. <nw...@is...> - 2001-07-18 14:54:55
|
"Paul F. Dubois" schrieb: > Using the outer product you get a matrix that has the right size and > contents but it is m*n by p*q > Was that a misprint in your post? > >>> x > array([1, 2, 3, 4, 5, 6]) > >>> x.shape=(3,2) > >>> y = 10*transpose(x) > >>> y > array([[10, 30, 50], > [20, 40, 60]]) > >>> z = outerproduct(x.flat, y.flat) > >>> z > array([[ 10, 30, 50, 20, 40, 60], > [ 20, 60, 100, 40, 80, 120], > [ 30, 90, 150, 60, 120, 180], > [ 40, 120, 200, 80, 160, 240], > [ 50, 150, 250, 100, 200, 300], > [ 60, 180, 300, 120, 240, 360]]) > >>> > > -----Original Message----- > From: num...@li... > [mailto:num...@li...]On Behalf Of Nils > Wagner > Sent: Wednesday, July 18, 2001 4:10 AM > To: num...@li... > Subject: [Numpy-discussion] Kronecker product > > Hi, > > I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. > > Nils > > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/lists/listinfo/numpy-discussion >>> a > array([[1, 2], > [3, 4]]) > >>> b > array([[11, 12], > [13, 14]]) > >>> outerproduct(a,b) > array([[11, 12, 13, 14], > [22, 24, 26, 28], > [33, 36, 39, 42], > [44, 48, 52, 56]]) The Kronecker product applied to A,B is kron(A,B) = array([[11,12,22,24], [13,14,26,28], [33,36,44,48], [39,42,52,56]]) How can I rearrange the result of outerproduct to the result of Kronecker product with numpy ? Cheers, Nils |
From: Charles G W. <cg...@al...> - 2001-07-18 15:05:22
|
Nils Wagner writes: > > How can I rearrange the result of outerproduct to the result of > Kronecker product with numpy ? > def kron(a,b): o = outerproduct(a,b) o.shape = a.shape + b.shape return concatenate(concatenate(o, axis=1), axis=1) |
From: Konrad H. <hi...@cn...> - 2001-07-18 15:22:36
|
> I would appreciate it, if Numpy could handle the Kronecker-product of > two matrices X, Y. > > kron(X,Y) is the Kronecker tensor product of X and Y. import Numeric def kron(x, y): return Numeric.multiply.outer(x, y) > The result is a large matrix formed by taking all possible products > between the elements of X and those of Y. If X is m-by-n > and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. OK, there's one difference: the function shown about returns an array of shape (m, n, p, q). If the input arrays are always 2D, the following will do what you need: import Numeric def kron(x, y): z = Numeric.transpose(Numeric.multiply.outer(x, y), [0, 2, 1, 3]) z.shape = (z.shape[0]*z.shape[1], z.shape[2]*z.shape[3]) return z Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hi...@cn... Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- |
From: Nils W. <nw...@is...> - 2001-07-19 08:15:43
Attachments:
kronecker1.py
|
Charles G Waldman schrieb: > Nils Wagner writes: > > > > How can I rearrange the result of outerproduct to the result of > > Kronecker product with numpy ? > > > > def kron(a,b): > o = outerproduct(a,b) > o.shape = a.shape + b.shape > return concatenate(concatenate(o, axis=1), axis=1) What is the difference between kron(z,eye) and kron(yt,eye) ? Nils |