Fwd: [Numpy-discussion] Re: inconsistent use of axis= keyword argument?
Alan G Isaac
aisaac at american.edu
Sat Feb 25 13:25:06 CST 2006
On Sat, 25 Feb 2006, Nils Wagner apparently wrote:
> Is it possible to use aliases for these operators ?
> In textbooks (Matrix Algebra by Abadir and Magnus,
> Cambridge University Press (2005)) you will find
> The vec-operator transforms a matrix into a vector by
> stacking its columns one underneath the other.
At http://www.american.edu/econ/pytrix/pyGAUSS.py
you will find these vec operations
(as GAUSS "look alikes").
hth,
Alan Isaac
#vec: vectorize columns of 2-D array
# Format: y = vec(x)
# Input: x RxK 2-D array (or matrix)
# Output: y (RK)x1 2-D array:
# stacked columns of x
# Remarks: ravel OK for non-contiguous arrays
# Author: Alan G Isaac (aisaac AT american DOT edu)
# Date: 20050420
def vec(x):
assert(len(x.shape)==2), "For 2-d arrays only."
return x.transpose().ravel().reshape((x.size,-1))
#vecr: vectorize rows of 2-D array
# Format: y = vecr(x)
# Input: x RxK 2-D array (or matrix)
# Output: y (RK)x1 2-D array:
# stacked rows of x
# Remarks: ravel OK for non-contiguous arrays
# Author: Alan G Isaac (aisaac AT american DOT edu)
# Date: 20050420
def vecr(x):
assert(len(x.shape)==2), "For 2-d arrays only."
return x.ravel().reshape((x.size,-1))
More information about the Numpy-discussion
mailing list