In [5]: scipy.sparse.csr_matrix([[1, 2], [3, 0]])
Out[5]:
<2x2 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
In [6]: scipy.sparse.csr_matrix([1, 2])
Out[6]:
<1x2 sparse matrix of type '<type 'numpy.int64'>'
with 2 stored elements in Compressed Sparse Row format>
Run Code Online (Sandbox Code Playgroud)
scipy.sparse.whatever_matrix_type(your_data_structure).这与你为获得常规阵列所做的非常类似.请注意,没有稀疏矢量或稀疏ndarray类,只有稀疏矩阵.