Hi all, it would be nice if the following function could be added to basic.py in /Lib/linalg from scipy import * def vec(a): """vec function of the matrix a is the vector formed by stacking the columns of a on top of one another Reference: Alan J. Laub, Matrix Analysis for Scientists & Engineers SIAM 2005 """ if not a.iscontiguous(): a = reshape(a, a.shape) return concatenate(transpose(a)) # # A short test # a = rand(3,3) b = rand(3,3) c = rand(3,3) d = dot(a,dot(b,c)) x1 = vec(d) x2 = dot(linalg.kron(transpose(c),a),vec(b)) print 'x1-x2 should be zero',linalg.norm(x1-x2) Nils
1. I prefer the solution you can find in pyGAUSS: def vec(x): return transpose([ravel(transpose(x))]) def vecr(x): return transpose([ravel(x)]) In particular, I prefer to get back a 2-D array. 2. I suppose someone familiar with tensors should address the proper generalization beyond 2-D inputs. fwiw, Alan Isaac
On Wed, 20 Apr 2005 13:21:40 -0400 (Eastern Daylight Time) Alan G Isaac <aisaac@american.edu> wrote:
1. I prefer the solution you can find in pyGAUSS: def vec(x): return transpose([ravel(transpose(x))]) def vecr(x): return transpose([ravel(x)]) In particular, I prefer to get back a 2-D array. 2. I suppose someone familiar with tensors should address the proper generalization beyond 2-D inputs.
fwiw, Alan Isaac
Just a suggestion. And how about the reverse ? a = rand(3,3) b = vec(a) a = transpose(reshape(a,(3,3))) # not the best way Nils
_______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.net http://www.scipy.net/mailman/listinfo/scipy-dev
Alan G Isaac wrote:
1. I prefer the solution you can find in pyGAUSS: def vec(x): return transpose([ravel(transpose(x))]) def vecr(x): return transpose([ravel(x)]) In particular, I prefer to get back a 2-D array. 2. I suppose someone familiar with tensors should address the proper generalization beyond 2-D inputs.
fwiw, Alan Isaac
_______________________________________________ Scipy-dev mailing list Scipy-dev@scipy.net http://www.scipy.net/mailman/listinfo/scipy-dev
Please can you add these functions to basic.py. Thanks in advance Nils
Alan G Isaac wrote:
1. I prefer the solution you can find in pyGAUSS: def vec(x): return transpose([ravel(transpose(x))]) def vecr(x): return transpose([ravel(x)]) In particular, I prefer to get back a 2-D array. 2. I suppose someone familiar with tensors should address the proper generalization beyond 2-D inputs.
On Thu, 21 Apr 2005, Nils Wagner wrote:
Please can you add these functions to basic.py.
I apologize if I gave the impression that I am a SciPy developer. But pyGAUSS is under the MIT license, so this (trivial) code is unencumbered if you can persuade a developer to include it. I agree that vec and vecr are basic functionality. But I do not know how they should generalize beyond 2-D inputs. Cheers, Alan Isaac
participants (3)
-
Alan G Isaac -
Alan Isaac -
Nils Wagner