I would like to know the best way to check if a scipy sparse matrix, if CSC or CSR. Right now I'm using.

```
rows, cols = X.shape()
indptr = X.indptr()
if len(indptr) == cols + 1:
print "csc"
else:
print "csr"
```

Thanks.

It looks like you could use the `.getformat()`

method:

```
>>> m0 = scipy.sparse.csc_matrix([1])
>>> m0.getformat()
'csc'
>>> m1 = scipy.sparse.csr_matrix([1])
>>> m1.getformat()
'csr'
```

You could check the class

```
m0=sparse.csc_matrix([1])
In [4]: type(m0).__name__
Out[4]: 'csc_matrix'
In [5]: isinstance(m0,sparse.csc_matrix)
Out[5]: True
In [6]: isinstance(m0,sparse.csr_matrix)
Out[6]: False
In [9]: sparse.isspmatrix_csc(m0)
Out[9]: True
In [10]: sparse.isspmatrix_csc??
...
def isspmatrix_csc(x):
return isinstance(x, csc_matrix)
```

Similar Questions

I'm trying to find a way to subtract a column of a scipy.sparse matrix from a numpy vector but I can't seem to find a way to do it without changing the shape of the vector. This is what I have so far:

As I understand LU factorization, it means that a matrix A can be written as A = LU for a lower-triangular matrix L and an upper-triangular matrix U. However, the functions in scipy relating to LU fac

Say I would like to remove the diagonal from a scipy.sparse.csr_matrix. Is there an efficient way of doing so? I saw that in the sparsetools module there are C functions to return the diagonal. Based

I have a question about Eigen library in C++. Actually, I want to calculate inverse matrix of sparse matrix. When I used Dense matrix in Eigen, I can use .inverse() operation to calculate inverse of d

I am using mex bridge to perform some operations on Sparse matrices from Matlab. For that I need to convert input matrix into CSR (compressed row storage) format, since Matlab stores the sparse matric

There is a nonzero() method for the csr_matrix of scipy library, however trying to use that function for csr matrices result in an error, according to the manual that should return a tuple with row an

What's the best way to find the maximum value and their corresponding row and column indices in a Scipy sparse lil_matrix object ? I can loop through the nonzero entries using itertools.izip, but is t

I have encountered a difference in how slicing a scipy sparse matrix works in 0.10.0 and 0.10.1. Consider the following piece of code: from numpy import array, ravel from scipy.sparse import csr_matri

I'm having trouble resizing a matrix - the set_shape function seems to have no effect: >>> M <14x3562 sparse matrix of type '<type 'numpy.float32'>' with 6136 stored elements in LInk

I have this sparse matrix of size 20 millionx20million in matlab. I want to get around 40000 specific rows from this matrix. If I do new_data = data_original(index,:) where index consists of the rows

When using pytables, there's no support (as far as I can tell) for the scipy.sparse matrix formats, so to store a matrix I have to do some conversion, e.g. def store_sparse_matrix(self): grp1 = self.g

One of my vector is in format scipy.sparse.csr.csr_matrix, the other is numpy.ndarray. I have an experimental code below: import numpy as np from scipy.sparse import csr_matrix x = np.arange(5)+1 y =

I'm working in a program for Power System analysis and I need to work with sparse matrices. There is a routine where I fill a sparse matrix just with the following call: self.A = bsr_matrix((val, (row

I am not undetstanding the difference between coo_matrix, csr_matrix and csc_matrix. The documentation does mention that coo_matrix is not efficient for arithmetic operations and we need to convert it

I have to invert a large sparse matrix. I cannot escape from the matrix inversion, the only shortcut would be to just get an idea of the main diagonal elements, and ignore the off-diagonal elements (I

preface: As the matlab guiderules state, Usually, when one wants to efficiently populate a sparse matrix in matlab, he should create a vector of indexes into the matrix and a vector of values he wants

I have a N*N matrix: N=3 x = scipy.sparse.lil_matrix( (N,N) ) for _ in xrange(N): x[random.randint(0,N-1),random.randint(0,N-1)]=random.randint(1,100) Assume the matrix looks as below: X Y Z X 0 [2,

Edit: The huge difference in performance is due to a bug in the test, when set up properly Eigen is 2 to 3 times faster. I noticed that sparse matrix multiplication using C++ Eigen library is much slo

I have never use R ,but now I need import a sparse matrix to do association rule in R My import data is a sparse matrix like this: i j x 1 2 3 1 2 3 5 1 3 3 1

How can you take the log base 10 of every element in a sparse matrix (COO)? >>print type(X) <class 'scipy.sparse.coo.coo_matrix'> I've tried this but it doesn't work: import math X.data =

What is the best way to efficiently remove columns from a sparse matrix that only contain zeros. I have a matrix which I have created and filled with data: matrix = sp.sparse.lil_matrix((100, 100)) I

I'd like to find the N smallest eigenvalues of a sparse matrix in Python. I've tried using the scipy.sparse.linalg.eigen.arpack package, but it is very slow at computing the smallest eigenvalues. I re

I have a list of sparse vectors (in R). I need to convert this list to a sparse matrix. Doing it via a for-loop takes a long time. sm<-spMatrix(length(tc2),n.col) for(i in 1:length(tc2)){ sm[i,]<

I'm coding the program that using linked list to store a sparse matrix. First I create a class Node contains the index of entry, value of entry and two pointers to next row and next column. Second I

What's the best way to apply something like scipy.misc.logsumexp to a sparse matrix (for instance a scipy.sparse.csr_matrix), specifying one axis? The point is to leave the zeros out from the computat

I am trying to compute nearest neighbour clustering on a Scipy sparse matrix returned from scikit-learn's DictVectorizer. However, when I try to compute the distance matrix with scikit-learn I get an

I am attempting to multiply two relatively large scipy.sparse matrices. One is 100000 x 20000 and the other is 20000 x 100000. My machine has sufficient memory to handle the operation but it is by no

In the context of a finite element problem, I have a 12800x12800 sparse matrix. I'm trying to solve the linear system just using MATLAB's \ operator to solve and I get an out of memory error using mld

In working with some text data, I'm trying to join an np array(from a pandas series) to a csr matrix. I've done the below. #create a compatible sparse matrix from my np.array. #sparse.csr_matrix(X['l

I have a very large Scipy sparse matrix ( CSR_MATRIX ). I just want to know how i can compute the sum of values for each row and also the sum of values for each column of the matrix. I have a code tha

I want to multiply a sparse matrix A, with a matrix B which has 0, -1, or 1 as elements. To reduce the complexity of the matrix multiplication, I can ignore items if they are 0, or go ahead and add th

I am trying to add a numpy ndarray to a sparse matrix and I have been unsuccessful in doing so. I was wondering if there is a way to do so, without transforming my sparse matrix into a dense one. ano

I have a sparse matrix that is not symmetric I.E. the sparsity is somewhat random, and I can't count on all the values being a set distance away from the diagonal. However, it is still sparse, and I w

I have a large scipy.sparse.csc_matrix and would like to normalize it. That is subtract the column mean from each element and divide by the column standard deviation (std)i. scipy.sparse.csc_matrix ha

Scipy and Numpy have between them three different functions for finding eigenvectors for a given square matrix, these are: numpy.linalg.eig(a) scipy.linalg.eig(a), and scipy.sparse.linalg.eig(A, k)

I need to insert the zero elements in any sparse matrix in the Matrix Market format (but already without the headers). The first column is the number of the ROW, the second columns is the number of th

I'm a bit of a newbie to both Matlab and Python so, many apologies if this question is a bit dumb... I'm trying to convert some Matlab code over to Python using numpy and scipy and things were going f

You have an original sparse matrix X: >>print type(X) >>print X.todense() <class 'scipy.sparse.csr.csr_matrix'> [[1,4,3] [3,4,1] [2,1,1] [3,6,3]] You have a second sparse matrix Z,

Does anyone know that how to use scipy.sparse package to compute SVD on sparse matrix? I know that I need to use scipy.sparse.linalg.svds(). But I did as bellow: from scipy.sparse import * csr = csr_

I know there are quite a few good ways to store a sparse matrix without taking up much memory. But I'm wondering whether there is a good way to store a sparse matrix during the construction of it? Her

I have a large sparse numpy/scipy matrix where each row corresponds to a point in high-dimensional space. I want make queries of the following kind: Given a point P (a row in the matrix) and a distanc

I have an assignment where Im supposed to finish the implementation on a generic sparse matrix. Im stuck on the addition part. The matrix is only going to support numbers so I had it extend Number hop

i have two sq matrix (a, b) of size in order of 100000 X 100000. I have to take difference of these two matrix (c = a-b). Resultant matrix 'c' is a sparse matrix. I want to find the indices of all non

Well, Trying to do something with search engines. I have generated a matrix (term-document) from a collection of 5 documents. The output is: docs= (5,1) 1.0000 (1,2) 0.7071 (3,2) 0.7071 (1,3) 0.7071

How can I create a sparse matrix from a list of dimension names? Suppose you have this matrix edgelist in a data frame: from to weight 1 4 a 1 2 5 b 2 3 6 c 3 It can be created like this: from <-

I am using the C++ Eigen 3 library in my program. In particular, I need to multiply two Eigen sparse matrix and store the result into another Eigen sparse matrix. However, I noticed that if the some e

I have a very large sparse matrix in Octave and I want to get the variance of each row. If I use std(A,1); it crashes because memory is exhausted. Why is this? The variance should be very easy to calc

What is the state of the art for fastest linear solver for sparse, positive semi definite and strictly diagonally dominant matrix with N varies from ~700 to ~3000, and about a 1/16 of the matrix is no

Has anybody implemented Blocked CSR/ELL SPMV in CUDA?? Where can I get the source code?. I'm finding it hard to block the matrix in CSR format

I'm trying to transpose a sparse matrix in c++. I'm struggling with the traversal of the new transposed matrix. I want to enter everything from the first row of the matrix to the first column of the n