Re: [SciPy-dev] sparse matrix support status
by Jonathan Guyer other posts by this author
Nov 23 2005 11:27AM messages near this date
Re: [SciPy-dev] sparse matrix support status
|
Re: [SciPy-dev] sparse matrix support status
On Nov 22, 2005, at 6:09 PM, Ed Schofield wrote:
> I have only one question for now. Could you please explain the comment
>
> >Â dok_matrix.setdiag() appears to change the matrix shape if you're not
> > careful, rendering it pretty useless for building the matrices for
> this
> > problem
>
> in more detail? The code for setdiag() is:
>
> Â Â Â def setdiag(self, values, k=0):
> Â Â Â Â N = len(values)
> Â Â Â Â for n in range(N):
> Â Â Â Â Â Â self[n, n+k] = values[n]
> Â Â Â Â return
>
> which grows the matrix only if it's currently smaller than len(values)
> x len(values). What's the problem this behaviour caused?  Would you
> prefer to fix the size of a dok_matrix in advance and have a run-time
> check on the len(values)? Or was the problem with the second
> argument?
Well, I guess I find the result of:
> >> B = scipy.sparse.dok_matrix((3,3))
> >> a = scipy.ones((3,))
> >> B.setdiag(a,0)
> >> print B.todense()
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
> >> B.setdiag(a,1)
> >> print B.todense()
[[ 1. 1. 0. 0.]
[ 0. 1. 1. 0.]
[ 0. 0. 1. 1.]]
to be surprising.
I was expecting
[[ 1. 1. 0.]
[ 0. 1. 1.]
[ 0. 0. 1.]]
This may not be a reasonable expectation, and I'm not sure where I came
by it, since neither PySparse nor Numeric seems to support sticking
anything into a diagonal, much less something that's too long.
Still, I think if I created an NxM matrix, then I probably want an NxM
matrix.
--
Jonathan E. Guyer, PhD
Metallurgy Division
National Institute of Standards and Technology
<http://www.metallurgy.nist.gov/>
_______________________________________________
Scipy-dev mailing list
Scipy-dev@[...].net
http://www.scipy.net/mailman/listinfo/scipy-dev
Thread:
Travis Oliphant
Robert Cimrman
Travis Oliphant
Robert Cimrman
Fernando Perez
Jonathan Guyer
Fernando Perez
Jonathan Guyer
Jonathan Guyer
Robert Cimrman
Jonathan Guyer
Ed Schofield
Jonathan Guyer
Ed Schofield
Travis Oliphant
Jonathan Guyer
Nils Wagner
Jonathan Guyer
Robert Cimrman
Robert Kern
Robert Cimrman
Travis Oliphant
Fernando Perez
Jonathan Guyer
Travis Oliphant
Nils Wagner
Jeff Whitaker
Nils Wagner
|