toarray returns an ndarray; todense returns a matrix. If you want a matrix, use todense ; otherwise, use toarray .
todense(order=None, out=None)[source] Return a dense matrix representation of this matrix. Parameters order{'C', 'F'}, optional. Whether to store multi-dimensional data in C (row-major) or Fortran (column-major) order in memory. The default is 'None', which provides no ordering guarantees.
Numpy matrices are strictly 2-dimensional, while numpy arrays (ndarrays) are N-dimensional. Matrix objects are a subclass of ndarray, so they inherit all the attributes and methods of ndarrays.
The function csr_matrix() is used to create a sparse matrix of compressed sparse row format whereas csc_matrix() is used to create a sparse matrix of compressed sparse column format.
toarray
returns an ndarray; todense
returns a matrix. If you want a matrix, use todense
; otherwise, use toarray
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With