slicing in scipy.sparse

10 views
Skip to first unread message

Anil Raj

unread,
Oct 21, 2009, 3:21:57 PM10/21/09
to apam-pyt...@googlegroups.com
Hi all,
I'm trying to extract a matrix from a larger one (in scipy.sparse.coo
format). Given a list of indices idx and a matrix A, I want to extract
Asub of size
len(idx) x len(idx) such that Asub[i,j] = A[idx[i],idx[j]].

Could anyone suggest a neat way to do this?

Thanks much!
Anil

Ian Langmore

unread,
Oct 21, 2009, 9:51:07 PM10/21/09
to apam-pyt...@googlegroups.com
I'm not sure about how to do that. By the way, did you check the
performance of a matvec using scipy.sparse? When I did it was very
slow. I populated the diagonal and compared it to a dense matrix with
the same values. The sparse matvec was 100 times slower, but maybe I
did something wrong.

Sent from my iPhone

Lisandro Dalcin

unread,
Oct 21, 2009, 10:35:48 PM10/21/09
to apam-pyt...@googlegroups.com
On Wed, Oct 21, 2009 at 10:51 PM, Ian Langmore <ianla...@gmail.com> wrote:
>
> I'm not sure about how to do that.  By the way, did you check the
> performance of a matvec using scipy.sparse? When I did it was very slow.  I
> populated the diagonal and compared it to a dense matrix with the same
> values.  The sparse matvec was 100 times slower, but maybe I did something
> wrong.
>

Did you converted the scipy.sparse to CSR format before testing the
matvec operations?


> Sent from my iPhone
>
> On Oct 21, 2009, at 3:21 PM, Anil Raj <anil....@gmail.com> wrote:
>
>>
>> Hi all,
>> I'm trying to extract a matrix from a larger one (in scipy.sparse.coo
>> format). Given a list of indices idx and a matrix A, I want to extract
>> Asub of size
>> len(idx) x len(idx) such that  Asub[i,j] = A[idx[i],idx[j]].
>>
>> Could anyone suggest a neat way to do this?
>>
>> Thanks much!
>> Anil
>

--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594

Anil Raj

unread,
Oct 21, 2009, 11:26:39 PM10/21/09
to apam-pyt...@googlegroups.com
yeah, the fastest matvec operations are when the matrix is in CSR
format. CSC format is about 10 times slower and I get dense to be 100
times slower. ( I tried a diagonal matrix with random entries and a
random vector)

Ian Langmore

unread,
Oct 22, 2009, 9:07:56 AM10/22/09
to apam-pyt...@googlegroups.com
I did convert it to csr, but may have screwed something else up.
Maybe I should try it again.

Sent from my iPhone

Reply all
Reply to author
Forward
0 new messages