2020_High_Performance_Python_-or_Humans_O'Reilly_Media,_Inc. 580.pdf

This preview shows page 1 out of 1 page.

The preview shows page 1 - 1 out of 1 page.
then simply say “all other values are zero.” In addition to these memorysavings, many algorithms have special ways of dealing with sparse matri‐ces that give additional computational benefits:>>>fromscipyimportsparse>>>A_sparse=sparse.random(2048,2048,0.05).tocsr()>>>A_sparse<2048x2048 sparse matrix oftype'<class 'numpy.float64'>'with209715stored elementsinCompressed Sparse Row format>>>> %timeit A_sparse*A_sparse150ms±1.71ms per loop(mean±std.dev.of7runs,10loopseach)>>>A_dense=A_sparse.todense()>>>type(A_dense)numpy.matrix>>> %timeit A_dense*A_dense571ms±14.5ms per loop(mean±std.dev.of7runs,1loop each)The simplest implementation of this is forCOOmatrices in SciPy, where
End of preview. Want to read the entire page?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
SDesousa
Tags
Matrices, coo, 66

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture