Last active
October 10, 2017 09:59
-
-
Save myui/dd07eb7a4d14fe879b6a357c06bdb822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy import array | |
from scipy.sparse import coo_matrix | |
row = np.array([82, 8, 56, 86, 48, 20, 22, 98, 65, 98]) | |
col = np.array([80, 13, 51, 74, 16, 40, 64, 57, 40, 30]) | |
data = np.array([0.6805822, 0.23116356, 0.8527678, 0.3512172, 0.03575957, 0.2307719, 0.6499588, 0.66925836, 0.8698123, 0.041548133]) | |
coo = coo_matrix((data, (row, col)), shape=(100, 100)) | |
>>> csr.indices | |
array([13, 40, 64, 16, 51, 40, 80, 74, 30, 57], dtype=int32) | |
>>> csr.data | |
array([ 0.23116356, 0.2307719 , 0.6499588 , 0.03575957, 0.8527678 , | |
0.8698123 , 0.6805822 , 0.3512172 , 0.04154813, 0.66925836]) | |
>>> csr.indptr | |
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | |
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, | |
4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, | |
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, | |
7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10], dtype=int32) | |
>>> csr.indptr.size | |
101 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/scipy/scipy/blob/11b1ebe4f4dd8c605501dad17fb416f006231442/scipy/sparse/sparsetools/coo.h#L34