[Numpy-discussion] Release of NumPy
Thu Apr 17 10:45:06 CDT 2008
Since I am the one who initially proposed the RowVector/ColumnVector
idea, I have followed the discussion here with interest. However,
since I typically deal with sparse matrices, I didn't feel like I had
much to contribute to the indexing issues. But now that we are
getting into sparse matrices, that has changed a little....
On Apr 17, 2008, at 9:11 AM, Travis E. Oliphant wrote:
> Alan G Isaac wrote:
>> What is more, Travis's question seems
>> to kill my proposal, since it seems to
>> imply that
> I didn't intentionally mean to do that.
>> - the behavior of matrices and sparse matrices
>> should match
> This is what I would like.
>> - that x should yield a sparse matrix if x is
>> a sparse matrix
> This is what is debatable.
So, I would expect to be able to access S[i,j], where S is a sparse
matrix, and get 0 if (i,j) is not stored, and the correct value if
(i,j) is stored. This would be consistent behavior with dense
matrices. But what should S[i] return, (or S[:,j])?
Along the lines of RowVector/ColumnVector, we could define
SparseRowVector/SparseColumnVector classes, which would provide the
expected behavior. Internally, they would store non-zero elements,
and their corresponding indexes. Externally, v[i] (where v is one of
the SparseVector classes) would just return the appropriate (zero or
non-zero) value. Then
S[i] -> SparseRowVector
S[:,j] -> SparseColumnVector
This would be consistent behavior between dense and sparse matrices
and support proper M[i][j] access. I don't know what iterating over a
SparseVector would mean/imply.
And it provides an example of the additional capabilities Alan has
been asking about.
(I am assuming here a compressed-row or compressed-column storage
format, but I think it could apply to other sparse matrix formats as
** Bill Spotz **
** Sandia National Laboratories Voice: (505)845-0170 **
** P.O. Box 5800 Fax: (505)284-0154 **
** Albuquerque, NM 87185-0370 Email: email@example.com **
More information about the Numpy-discussion