[Scipy-tickets] [SciPy] #1533: toarray on sparse matrices can't handle dtype=bool

SciPy Trac scipy-tickets@scipy....
Mon Mar 4 20:31:59 CST 2013


#1533: toarray on sparse matrices can't handle dtype=bool
--------------------------+-------------------------------------------------
 Reporter:  larsmans      |       Owner:  wnbell     
     Type:  defect        |      Status:  new        
 Priority:  high          |   Milestone:  Unscheduled
Component:  scipy.sparse  |     Version:  0.9.0      
 Keywords:                |  
--------------------------+-------------------------------------------------
Changes (by agrothberg):

  * priority:  normal => high


Comment:

 I am seeing the same issue with:


 {{{
 >>>csr_matrix(numpy.array([True, True, False]),dtype=numpy.bool)
 <1x3 sparse matrix of type '<type 'numpy.bool_'>'
         with 2 stored elements in Compressed Sparse Row format>
 }}}

 and then


 {{{
 csr_matrix(numpy.array([True, True, False]),dtype=numpy.bool).toarray()

 TypeError                                 Traceback (most recent call
 last)
 <ipython-input-31-3cea59b044f4> in <module>()
 ----> 1 csr_matrix(numpy.array([True, True,
 False]),dtype=numpy.bool).toarray()

 /usr/lib/python2.7/dist-packages/scipy/sparse/compressed.pyc in
 toarray(self)
     548
     549     def toarray(self):
 --> 550         return self.tocoo(copy=False).toarray()
     551
     552     ##############################################################

 /usr/lib/python2.7/dist-packages/scipy/sparse/coo.pyc in toarray(self)
     238         B = np.zeros(self.shape, dtype=self.dtype)
     239         M,N = self.shape
 --> 240         coo_todense(M, N, self.nnz, self.row, self.col, self.data,
 B.ravel())
     241         return B
     242

 /usr/lib/python2.7/dist-packages/scipy/sparse/sparsetools/coo.pyc in
 coo_todense(*args)
     170         npy_clongdouble_wrapper Bx)
     171     """
 --> 172     return _coo.coo_todense(*args)
     173
     174 def coo_matvec(*args):

 TypeError: Array of type 'byte' required.  Array of type 'bool' given
 }}}

 why does the type show up at numpy.bool_ rather than numpy.bool?

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1533#comment:1>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list