[SciPy-user] Sparse Boolean matrix
Nils Wagner
nwagner at iam.uni-stuttgart.de
Tue Jun 10 13:41:53 EDT 2008
On Tue, 10 Jun 2008 19:21:14 +0200
"Lukas Michelbacher" <michells at ims.uni-stuttgart.de>
wrote:
> As the title says I'd like to use a matrix with Boolean
>values in some
> sparse format.
> My problem is that even though initialization seems to
>works fine, the
> matrix doesn't
> contain Boolean values but the default float type.
>
> In [18]: A = sparse.csr_matrix((1000,1000), dtype=bool)
>
> In [19]: A
> Out[19]:
> <1000x1000 sparse matrix of type '<type
>'numpy.float64'>'
> with 0 stored elements (space for 100)
> in Compressed Sparse Row format>
>
> The same happens for CSC, LIL and COO formats.
>
> I use SciPy 0.6.0
>>> from scipy import *
>>> A = sparse.csr_matrix((1000,1000), dtype=bool)
>>> A
<1000x1000 sparse matrix of type '<type 'numpy.bool_'>'
with 0 stored elements in Compressed Sparse Row
format>
>>> scipy.__version__
'0.7.0.dev4423'
>>> A = sparse.coo_matrix((1000,1000), dtype=bool)
>>> A
<1000x1000 sparse matrix of type '<type 'numpy.bool_'>'
with 0 stored elements in COOrdinate format>
>>> A = sparse.lil_matrix((1000,1000), dtype=bool)
>>> A
<1000x1000 sparse matrix of type '<type 'numpy.bool_'>'
with 0 stored elements in LInked List format>
>>> A = sparse.dok_matrix((1000,1000), dtype=bool)
>>> A
<1000x1000 sparse matrix of type '<type 'numpy.bool_'>'
with 0 stored elements in Dictionary Of Keys
format>
Nils
More information about the SciPy-User
mailing list