I was trying to iterate over the non zero elements of a row major sparse matrix, such as shown below:

```
Eigen::SparseMatrix<double,Eigen::RowMajor> Test(2, 3);
Test.insert(0, 1) = 34;
Test.insert(1, 2) = 56;
for (int k = 0; k < Test.outerSize(); ++k){
for (Eigen::SparseMatrix<double>::InnerIterator it(Test, k); it; ++it){
cout << it.row() <<"\t";
cout << it.col() << "\t";
cout << it.value() << endl;
}
}
```

but I dont see the right values. Instead, I see random values for it.row(), a value of 1 for it.col() and some random value for it.value(), as shown below:

```
-17891602 1 -2.65698e+303
```

Changing RowMajor to ColumnMajor makes the code work as expected.

I am not sure what went wrong for the row major part ? Can someone please let me know what am I missing here ?

Thanks in advance

I'm surprised that it compiles fine: the type of your iterator is not correct. It must be a `SparseMatrix<double,Eigen::RowMajor>::InnerIterator`

.

Similar Questions

I wish to speed up my machine learning algorithm (written in Python) using Numba (http://numba.pydata.org/). Note that this algorithm takes as its input data a sparse matrix. In my pure Python impleme

It seems to me that in SAGE the only difference between creating a dense matrix and a sparse matrix is by the flag passed to the constructor (sparse = True). In particular, this means that if I want

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 have a sparse matrix (dgCMatrix) as the result of fitting a glmnet. I want to write this result to a CSV but can't use write.table() the matrix because it can't coerced into a data.frame. Is there a

consider the following test Eigen::MatrixXd B(Eigen::MatrixXd::Random(5,5)); const Eigen::MatrixXd C(Eigen::MatrixXd::Random(5,5)); std::cout << B << typeid(B).name() << std::endl

How do I iterate over each row in Z where Z is a 2 * m matrix: 6.1101,17.592 5.5277,9.1302 8.5186,13.662 How do I access each Z(i)(j) inside this loop? For example: for i = z fprintf('Iterating over

Are the class members of this simple class continous in memory? class A{ A(){ /* somecode */} ~A(); Eigen::Matrix<5,1,double> a; Eigen::Matrix<9,1,double> b; }; std::vector<A> vec(10

I am looking for the best package for sparse matrix multiplication on single core solution. I am not looking for CUDA, MPI or OpenMP solutions. My preference for languages in decreasing order : Matlab

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 need to create a matrix with values from a numpy array. The values should be distributed over the matrix lines according to an array of indices. Like this: >>> values array([ 0.73620381, 0.

When trying to run the cor() function on sparse matrices (of either type dgCMatrix or dgTMatrix) I get the following error: Error in cor(x) : supply both 'x' and 'y' or a matrix-like 'x' Converting m

I would like to make a correlation matrix like the one below. However, R keeps telling me 'Error in eigen(corr) : infinite or missing values in 'x'' Correlation matrix circles I think this may be ca

I'm using Python, Numpy and Scipy packages to do matrix computations. I am attempting to perform the calculation X.transpose() * W * X where X is a 2x3 dense matrix and W is a sparse diagonal matrix.

I need to overload [] operator in class Sparse Matrix. This operator must work like in 2D table access. For example tab[1][1], return reference. The problem is I have a vector of elements(struct). tem

What is the fastest way to convert 1/0 sparse matrix to 0/1 sparse matrix without using todense() method? Example: Source matrix looks like: matrix([[1, 1, 0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1,

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 a data structure created using read.csv() of dimensions 130, 395. I am trying to iterate over the data by row and return a vector containing a list of lists of the sum over each row in incremen

I have to compute massive similarity computations between vectors in a sparse matrix. What is currently the best tool, scipy-sparse or pandas, for this task?

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'm having trouble efficiently loading data into a sparse matrix format in R. Here is an (incomplete) example of my current strategy: library(Matrix) a1=Matrix(0,5000,100000,sparse=T) for(i in 1:5000)

In Java, is a multidimensional array stored in column-major or row-major order?

In a scipy program I'm creating a dia_matrix (sparse matrix type) with 5 diagonals. The centre diagonal the +1 & -1 diagonals and the +4 & -4 diagonals (usually >> 4, but the principle i

How do I raise a scipy.sparse matrix to a power, element-wise? numpy.power should, according to its manual, do this, but it fails on sparse matrices: >>> X <1353x32100 sparse matrix of typ

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 am currently working on a C program trying to compute Matrix Multiplication.. I have approached this task by looping through each column of the second matrix as seen below. I have set size to 1000.

I would like to get the minimum nonzero values per row in a sparse matrix. Solutions I found for dense matrices suggested masking out the zero values by setting them to NaN or Inf. However, this obvio

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 wanted to repeat the rows of a scipy csr sparse matrix, but when I tried to call numpy's repeat method, it simply treats the sparse matrix like an object, and would only repeat it as an object in an

I'm using the Eigen C++ matrix library, and I would like to obtain a reference to a column of a matrix. The documentation says to use matrix_object.col(index), but this appears to be returning an obje

Using the Eigen library in C++, given a sparse matrix A, what is the most efficient way (row-wise operations? how to?) to compute a sparse matrix B such that B(i, j) = A(i, j) / A(i, i) ? That is, div

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

Given an n by n matrix M, at row i and column j, I'd like to iterate over all the neighboring values in a circular spiral. The point of doing this is to test some function, f, which depends on M, to

I want to calculate SVD , but I didn't find good java library for this. Now, I have data store in hashmap, because matrix didn't fit into memory due to the fact that sizes are about 400 000 X 10 000 a

I see 2 implementations of sparse matrix in this package. OpenMapRealMatrix SparseFieldMatrix Both are documented as Sparse matrix implementation based on an open addressed map. Do you know what a

Below is my code for generating my sparse matrix: import numpy as np import scipy def sparsemaker(X, Y, Z): 'X, Y, and Z are 2D arrays of the same size' x_, row = np.unique(X, return_inverse=True) y_,

Can you iterate over a flat file with XSL? I'd like to ls>myfile for each line of myfile apply-template

In python if a define: a = arange(9).reshape(3,3) as a 3x3 matrix and iterate: for i in a: It'll iterate over the matrix's rows. Is there any way to iterate over columns?

Given a matrix m = [10i+j for i=1:3, j=1:4], I can iterate over its rows by slicing the matrix: for i=1:size(m,1) print(m[i,:]) end Is this the only possibility? Is it the recommended way? And what a

Can I use the Eigen library to get the rotation matrix which rotates vector A to vector B? I have been searching for a while, but cannot find related api.

I am using MATLAB to load a text file that I want to make a sparse matrix out of. The columns in the text file refer to the row indices and are double type. I need them to be integers to be able to us

I want to read a plain binary file containing a number of unsigned 16-bit integers into an Eigen matrix, and I wrote a templated utility to do this. This is what the caller looks like: Matrix<uint1

I have a 1034_by_1034 sparse matrix (scipy.sparse.csr.csr_matrix), which basically represents the adjacency matrix of a graph. I want to check if some elements are ones or not. But I found this to be

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

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

Hi, in java I use a json lib called JSONObject, (I don't mind switching if I need to). I know how to iterate over JSONArrays, but when I parse json data from facebook I don't get an array, only a JSO

When I create a matrix using Eigen, like this: Eigen::MatrixXd M(3,3); M<< 1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 3.0, 6.0, 9.0 ; std::cout<<M<<std::endl; produces 1 4 7 2 5 8 3 6 9 I can

I have three lists namely A , B , C All these lists contain 97510 items . I need to create a sparse matrix like this matrix[A[0]][B[0]] = C[0] For example , A=[1,2,3,4,5] B=[7,8,9,10,11] C=[14,15,1

I've got a sparse Matrix in R that's apparently too big for me to run as.matrix() on (though it's not super-huge either). The as.matrix() call in question is inside the svd() function, so I'm wonderin

I'm trying to cluster some data with python and scipy but the following code does not work for reason I do not understand: from scipy.sparse import * matrix = dok_matrix((en,en), int) for pub in pubs:

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