Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print whole sparse matrix?

Tags:

python

scipy

I want to print the whole matrix. When I print X it tells me location where values are stored expcept zeros. Can I print whole matrix including zeros?

X = sparse.csr_matrix(1./2.*np.array([[0.,1.],[1.,0.]]))
print(X)
like image 785
user10163680 Avatar asked Mar 05 '23 14:03

user10163680


1 Answers

You can convert the sparse matrix to dense (i.e. regular numpy matrix) and then print the dense representation. For this use the method todense.

Sample code:

X = sparse.csr_matrix(1./2.*np.array([[0.,1.],[1.,0.]]))
a = X.todense()
print(a)
like image 164
Ivaylo Strandjev Avatar answered Mar 15 '23 19:03

Ivaylo Strandjev