I need a command to check for zero sparse matrix, isempty(..) does not work. Is there some sparse version of isempty(..)?

```
>> mlf2=sparse([],[],[],2^31+1,1)
mlf2 =
All zero sparse: 2147483649-by-1
>> isempty(mlf2)
ans =
0 % I waited for 1 here with the zero sparse matrix...
```

Try

```
~nnz(mlf2)
```

or

```
isempty(find(mlf2))
```

**Edit:**

Mohsen Nosratinia pointed out that `isempty(find(mlf2), 1)`

is more efficient because it the `find`

command will either return a matrix of length 1, or an empty matrix

Similar Questions

Is there a sparse matrix library that copies the functionality of dense BLAS? I'd want at least: efficient SYR and SYRK (rank-k update) with sparse input (and possibly dense output), option for spars

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

How can a sparse matrix - matrix product be calculated? I know the 'classic' / mathematical way of doing it, but it seems pretty inefficient. Can it be improved? I thought about storing the first matr

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

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

Is there a way to compute the power of a sparse matrix in matlab without converting it to a full matrix. If I try b = a^0.5 where a is a sparse matrix, I get the error Use full(x)^full(y).. However

I want to initial a sparse matrix with numpy array. The numpy array contains NaN as zero for my program, the code to initial a sparse matrix as following: a= np.array([[np.NaN,np.NaN,10]]) zero_a= np.

I have a sparse logical matrix, which is quite large. I would like to draw random non-zero elements from it without storing all of its non-zero elements in a separate vector (eg. by using find command

I have a large 500x53380 sparse matrix and trying to dichotomize it. I have tried using event2dichot under sna package but no success because it requires an adjacency matrix or network object. I al

I am trying to find an efficient way that lets me increase the top k values of a sparse matrix by some constant value. I am currently using the following code, which is quite slow for very large matri

Suppose I have a sparse matrix Sparstica that is a vertical concatenation of several other sparse matrices. When I type Sparstica(:), I get a list of the nonzero elements. In the left column, will be

I'm writing a lexer generator as a spare time project, and I'm wondering about how to go about table compression. The tables in question are 2D arrays of short and very sparse. They are always 256 cha

Is there a built-in function in either slam package or Matrix package to convert a sparse matrix in simple triplet matrix form (from slam package) to a sparse matrix in dgTMatrix/dgCMatrix form (from

I am extremely new to the matlab programming language and am trying to accomplish the following task: (1,3) 0.0000 (2,3) 0.0000 (3,3) 0.0000 (4,3) 0.4803 (5,3) 0.0000 (6,3) 0.0000 (7,3) 0.0000 (8,3)

Finding the maximum sum subrectangle in an NxN matrix can be done in O(n^3) time using 2-d kadane's algorithm, as pointed out in other posts. However, if the matrix is sparse, specifically O(n) non-ze

I have got an output using sparse matrix in python, i need to store this sparse matrix in my hard disk, how can i do it? if i should create a database then how should i do?? this is my code: import nl

There are at least two sparse matrix packages for R. I'm looking into these because I'm working with datasets that are too big and sparse to fit in memory with a dense representation. I want basic lin

I have this huge sparse matrix A of size 2 million by 10 thousand. I want to index particular 1000 rows (index) from this matrix. If I do B = A(index,:); it takes some time. Is there a better quick

I am using MATLAB and having some issues formatting the output of a matrix. Currently, the matrix looks like: Columns 1 through 7 4 6 5 1 0 0 0 7 8 4 0 1 0 0 6 5 9 0 0 1 0 1 0 0 0 0 0 -1 0 1 0 0 0 0

I have a sparse matrix that I obtained by using Sklearn's TfidfVectorizer object: vect = TfidfVectorizer(sublinear_tf=True, max_df=0.5, analyzer='word', vocabulary=my_vocab, stop_words='english') tfid

If I am using the sparse.lil_matrix format, how can I remove a column from the matrix easily and efficiently?

My problem: I have 5-diagonal single-precision matrix with dimensions about 5000x5000 (so there are ~25000 non-zero elements there) and have to solve linear equation system. MATLAB made it for ~1 ms w

In my project, I'm trying to build an adjacency matrix for a graph, and for space and time considerations we are supposed to use a sparse matrix, which, from my understanding, is most easily done with

For Scipy sparse matrix, one can use todense() or toarray() to transform to Numpy.matrix or array. What are the functions to do the inverse? I searched, but got no idea what keywords should be the rig

I want to pass a sparse matrix to a shared library from MATLAB, do some operation there (written in C), and then return it. I can pass a dense matrix and use, pretty easy. But, I have no idea how to p

I am trying to find an efficient way to retrieve a list / vector / array of the non-zero upper triangular elements of a sparse matrix in R. For example: library(igraph) Gmini <- as.directed(graph.

I'm looking for a matrix / linear algebra library in Java that provides a sparse matrix that can be written to concurrently from different threads. Most of the libraries I've come across either do not

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

This Creating sparse matrix in MEX has a good example on mxCreateSparse. But this function return a double sparse matrix instead of single. If I want to return a single sparse matrix, what should I do

I have an N x N sparse matrix in Matlab, that has cell values indexed by (r,c) pairs such that r and c are unique id's. The problem is, that after converting this matrix into Python, all of the indic

I am loading a sparse matrix in MATLAB using the command: A = spconvert(load('mymatrix.txt')); I know that the dimension of my matrix is 1222 x 1222, but the matrix is loaded as 1220 x 1221. I know t

I have a matrix S something like: 1 4 7 2 5 8 3 6 9 Then I make a=complex(S{2},S{3}) and wanted to find the abs(a);. This is not possible in MATLAB as a is not an integer - it is a matrix. How can I

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 initialize an empty sparse matrix using S = scipy.sparse.lil_matrix((n,n),dtype=int) As expected print S doesn't show anything, since nothing has been assigned. Yet if I test: print S[0,0]==0 I r

In another post regarding resizing of a sparse matrix in SciPy the accepted answer works when more rows or columns are to be added, using scipy.sparse.vstack or hstack, respectively. In SciPy 0.12 the

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

I am filling a sparse matrix P (230k,290k) with values coming from a text file which I read line by line, here is the (simplified) code while ... C = textscan(text_line,'%d','delimiter',',','EmptyValu

I'm using numpy and scipy. I have a large sparse matrix and I want to find the largest eigenvalue of the sparse matrix. How can I do that?

I have a big (400K*400K) sparse matrix and I need to calculate the largest eigenvalue of A'*A. The problem is that Matlab can't even calculate A' due to memory problems. I also tried [a,b,c] = find(A)

I am attempting to cluster a set of data points that are represented as a sparse scipy matrix, X. That is, >>> print type(X) <class 'scipy.sparse.csr.csr_matrix'> >>> print X.s

I'm using the newest version of matlab. I'm plotting a matrix using the imagesc command with the jet colormap. The background values of the matrix are zero and are plotted in the image as the lowest c

I've created a TermDocumentMatrix from the tm library in R. It looks something like this: > inspect(freq.terms) A document-term matrix (19 documents, 214 terms) Non-/sparse entries: 256/3810 Sparsi

I have a Table in MySQL with three columns: row-index, column-index and value, which I want to read in into a scipy csr_matrix. I use the Python-MySQL connector. There are 112,500 non-zero elements. T

I am trying to find the dot product between a scipy sparse matrix and a numpy.ndarray. tensor refers to theano.tensor. X is the sparse matrix and W_hidden is the ndarray. b_hidden is also ndarray. te

I'm trying to construct a vandermonde matrix using matlab. My input vector is t = [ 1 2 3 4 ]' My output using the vander function is: ans = 1 1 1 1 8 4 2 1 27 9 3 1 64 16 4 1 Now if I'm not mistak

I have an AxB matrix and two binary column vectors, Ax1 and Bx1 in Matlab. How can i select the rows of the matrix corresponding to 1 of Ax1 vector? Obviously, I have to do the same operation on the c

I have two large, scipy sparse matrices, representing time series data. In the first, each row represents a user's music listening over a number of months (the columns), with each value in the row bei

I am using cusp for sparse matrix multiplication. From the resultant matrix i need the max value without copying the matrix from device memory to host memory. I am planning to wrap the resultant matri

Is there a way to generate N x N random diagonalizable matrix in MATLAB? I tried as following: N = 10; A = diag(rand(N,N)) but it is giving me an N x 1 matrix. I also need the matrix to be symmetric.

I'm wondering whether there is a way to simply add a dense vector to all the rows of a sparse matrix represented as a csr_matrixin scipy.sparse and returning a sparse matrix, ie trying to sum only the