I see with new Eigen 3.2, you can get row, column or even block from a sparse matrix, is there a way to set any of these to 0?

```
Eigen::SparseMatrix<float, Eigen::RowMajor> A( 5, 5 );
A.block(1, 1, 2, 2) = 0; // won't work
A.row(1) = 0; // won't work
A.col(1) = 0; // won't work
```

Thanks!

For 5x5 matrices, it is overkill to use a sparse matrix. Better use a `MatrixXd`

, or even a `Matrix<float,5,5>`

. In this case you can set a row to zero with `A.row(1).setZero()`

. Sparse matrices are worth it for matrices of size about 1000x1000 and greater.

Anyway, the best to suppress multiple columns and rows of a sparse matrix at once is to use the prune method. Here is an example removing the second row and third column:

```
#include <Eigen/Sparse>
#include <iostream>
using namespace Eigen;
int main()
{
Eigen::SparseMatrix<float, Eigen::RowMajor> A;
A = MatrixXf::Random(5,5).sparseView();
A.prune([](int i, int j, float) { return i!=1 && j!=2; });
std::cout << A << "\n";
}
```

Similar Questions

How translation a matrix(4x4) in Eigen? //identity matrix 4x4 /*type=*/Eigen::Matrix<float, 4, 4> /*name=*/result = Eigen::Matrix<float, 4, 4>::Identity(); //translation vector // 3.0f //

I have inherited some code which makes extensive use of double pointers to represent 2D arrays. I have little experience using Eigen but it seems easier to use and more robust than double pointers. Do

I came across the following assigning for a matrix in Eigen Library here Matrix3f m; m << 1, 2, 3, 4, 5, 6, 7, 8, 9; as an alternative way of the boring one (m(0,0) = 1; ... etc). My question i

Suppose I have a matrix in the CSR format, what is the most efficient way to set a row (or rows) to zeros? The following code runs quite slowly: A = A.tolil() A[indices, :] = 0 A = A.tocsr() I had to

I have a csv file with headers like: Given this test.csv file contains sparse matrix: A,B,C,D,E,F,timestamp 611.88243,0,0,0,0,0,0 0,9089.5601,0,864.07514,0,0,0 0,0,5133.0,0,0,0,0 I simp

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 have a square matrix C,of which I have to find the eigen values and eigen vectors. C = 2 -1 -1 0 -1 3 -1 -1 -1 -1 3 -1 0 -1 -1 2 When I use the function eig() such that, [V,D]=eig(C,'nobalance') Th

I am using scipy.sparse.linalg.eigsh to solve the generalized eigen value problem for a very sparse matrix and running into memory problems. The matrix is a square matrix with 1 million rows/columns,

Given an arbitrary numpy array (ndarray), is there a function or a short way to convert it to a scipy.sparse matrix? I'd like something that works like: A = numpy.array([0,1,0],[0,0,0],[1,0,0]) S = t

I noticed Pandas now has support for Sparse Matrices and Arrays. Currently, I create DataFrame()s like this: return DataFrame(matrix.toarray(), columns=features, index=observations) Is there a way to

I am building a sparse linear system with multiple (soft) constraints. I am converting some code which used to build the matrix with boost::ublas, to Eigen. The boost:ublas has a convenient way to cre

Given an image of size [hh,ww], I would like to create efficiently a sparse matrix of size [hh*ww, hh*ww]. For each 4- or 8-neighbor of a given pixel, the sparse matrix should be filled with a constan

I am trying to write a function that takes fixed size matrix using template on the matrix size. I have read http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html but I am not able to make

I have been working with computer matrix multiplications on last months and I have made some tests using openMP and eigen3. The tests were made on the follow machines: Computer 1: Intel Core i7-3610QM

I am trying to create a sparse matrix which has a 2D pattern run down the diagonal. This is probably easiest to explain with a quick example. Say my pattern is: [1,0,2,0,1]... I want to create a spars

I am working on a project that involves the computation of the eigenvectors of a very large sparse matrix. To be more specific I have a Matrix that is the laplacian of a big graph and I am interested

I'm trying to utilize the ODE integration capabilities of Boost using the Matrix class from Eigen 3 as my state vector, but I'm running into problems deep into Boost that I don't understand how to add

Does Eigen have efficient type for store dense, fixed-size, symmetric matrix? (hey, they are ubiquitous!) I.e. for N=9, it should store only (1+9)*9/2==45 elements and it has appropriate operations. F

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

How in Matlab we can form a matrix X, 1000 by 1000, which is sparse with, say, 5% of independent Bernoulli +-1 nonzero entries? I.e. such a matrix would have rho = ||X||_0/10^6 = 0.05.

I am trying to use the very recent capability of the RcppArmadillo package (version 0.3.910.0 with R 3.0.1 and evrerything up to date) for conversion of a sparse matrix from the Matrix package (class

I noticed on Google Summer of Code 2013 that a possible project was implement sparse matrix support for Decision Trees and ensemble methods. Out of curiosity, did this project get anywhere? I really n

Sorry for rookie question. I'm learning to work with scipy.sparse and I'm out of ideas why this code does not work. The dimensions are correct but the subtraction can not be computed: c=(count_mat[i])

I have further question continuing my previous question. Now I want to pass two kinds of Eigen parameters in one type: (1) fixed sized matrix or (2) rows is fixed but cols is dynamic. Both matrices's

I'm trying to set up a particular kind of sparse matrix in R. The following code gives the result I want, but is extremely slow: library(Matrix) f <- function(x){ out <- rbind(head(x, -1), tail(

I have sparse vectors with dimensionalities of around 200.000. I also have a matrix with the same amount of columns, and the same amount of rows as the number of vectors. I want to set all of these in

I have downloaded and included UJMP (Universal Java Matrix Package) library to my project for generating sparse matrix. But I could not find any documentation about functions of the library, how to cr

I have implemented a MCMC algorithm in C++ using the Eigen library. The main part of the algorithm is a loop in which first some some matrix calculations are performed after which the determinant of t

I have a fairly large sparse matrix that, I reckon, would occupy 1Gb when loaded into memory. I don't need access to the whole matrix at all times, so some kind of memory mapping would work; it doesn'

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 a data file storing a large matlab sparse matrix (matlab 7.3) that needs to be used in my python program. I use h5py to load this sparse matrix and find there are 3 data structures associated w

Question is very simple: Let's say I have a given row r from scipy sparse matrix M (100,000X500,000), I want to find its location/index in the M matrix? How can I accomplish this in an efficient way?

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

I'm currently working with sparse matrices, and I have to compare the computation time of sparse matrix-matrix multiplication with full matrix-matrix multiplication. The issue is that sparse matrix co

I have sparse CSR matrices (from a product of two sparse vector) and I want to convert each matrix to a flat vector. Indeed, I want to avoid using any dense representation or iterating over indexes. S

It takes 0.02 seconds for Matlab to compute the inverse of a diagonal matrix using the sparse command. P = diag(1:10000); P = sparse(P); tic; A = inv(P); toc However, for the Python code it takes for

I created a sparse matrix in MEX using mxCreateSparse. mxArray *W; W=mxCreateSparse(n*n,n*n,xsize,mxREAL); double *wpoint; wpoint=mxGetPr(W); for(p=0;p<xsize;p++) { Wpoint[(returnindex1(xi[p][0],xi

Given a sparse binary matrix A (csr, coo, whatever) I want to make a plot such that I can see the position (i,j) = white in the figure if A(i,j) = 1, and (i,j) = black if A(i,j) = 0; For a dense numpy

I have a large sparse matrix, implemented as a lil sparse matrix from sci-py. I just want a statistic for how sparse the matrix is once populated. Is there a method to find out this?

I'm trying to manipulate some data in a sparse matrix. Once I've created one, how do I add / alter / update values in it? This seems very basic, but I can't find it in the documentation for the sparse

I have: Eigen::MatrixXf load_from_gpu() { Eigen::MatrixXf mat(m_rows,m_cols); clEnqueueReadBuffer(m_manager->m_gpu_queue_loader, m_buffer, CL_TRUE, 0, sizeof(float)*numel(), mat.data(), 0, NULL, NU

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

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 currently trying to classify text. My dataset is too big and as suggested here, I need to use a sparse matrix. My question is now, what is the right way to add an element to a sparse matrix? Let's

I ran into the following issue trying to vstack two large CSR matrices: /usr/lib/python2.7/dist-packages/scipy/sparse/coo.pyc in _check(self) 229 raise ValueError('negative row index found') 230 if s

I have a very big and sparse matrix, represented as a CSV file (67 GB). Is it possible to load and work with this matrix in Matlab? I can use a 64bit version on a MAC OS computer, 8GB RAM. I have read

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 would like to extract specific rows and columns from a scipy sparse matrix - probably lil_matrix will be the best choice here. It works fine here: from scipy import sparse lilm=sparse.lil_matrix((10

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

I currently want to multiply a large sparse matrix(~1M x 200k) with its transpose. The values of the resulting matrix would be in float. I tried loading the matrix in scipy's sparse matrix and by mul