[SciPy-dev] small bug(s) in scipy.linalg

Alexander Schmolck a.schmolck at gmx.net
Mon Feb 10 09:25:59 CST 2003


Pearu Peterson <pearu at cens.ioc.ee> writes:

> On 10 Feb 2003, Alexander Schmolck wrote:
> 
> > I think scipy.linalg.basic has a few issues with 1D vectors vs row and column
> > vectors (respective shapes: (n,), (1,n), (n,1)). It would seem clear to me,
> > for example that `norm` ought to produce exactly the same with a 1D vector as
> > with a row vector or column vector. Currently it doesn't,
> 
> -1 for considering it as a bug.
> 
> For generality, I'd leave to users to decide whether (1,n) or
> (n,1) shaped matrices should regarded as vectors. 
> 

At first I didn't understand what you meant, but then I realized my mistake:
matrix norm and vector norm are *not* the same for row and column vectors for
e.g. infinity norms. 

One reason why I didn't realize the obvious difference earlier is that matlab
indeed treats vectors specially. So although the (matrix) infinity norm of a
row vector and a column vector should be different, they aren't -- matlab's
`norm` will in both cases compute the same result (the vector norm), although
matrix and vector infinity norm should only be the same for column vectors. It
thus appears to me that there is no way to calculate the matrix infinity norm
for 1xN matrices in matlab, without doing it by hand. This seems fairly
undesirable, but having a neutrally named `norm` function that gives different
results for column and row vectors also seems rather fairly undesirable. Hence
I'd propose that there should be separate functions, vector_norm and
matrix_norm (or something shorter like 'vnorm' and 'mnorm'), where vector_norm
only accepts arrays with shapes (n,), (1,n) and (n,1) and produces the same
results for all of them, whereas matrix_norm only accepts arrays with shape
(n,m) (mathematica seems to do something like this, BTW). Or is there any
reason I'm missing why one can write more general code if `norm` sometimes
computes the vector norm and sometimes the matrix norm, depending on the shape
of it first argument?

One more thing: in the docstring for `norm` the scipy defines the matrix
infinity norm as "the largest column sum" and the 1 norm as "the largest row
sum". Isn't that backwards (i.e. ``row_sum = sum(matrix,1)``)?  Matlab and
linear algebra books (e.g. Horn & Johnson, p.295) seem to have it like this at
least -- so although matlab's infinity norm of a matrix yields the same
answer, the doc defines it as "the largest *row* sum".


alex




More information about the Scipy-dev mailing list