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 (5,3) 0.7071 (3,4) 1.0000 (4,5) 1.0000**

Also, I have generated a query matrix from user query.

q= **(1,1) 1 (2,1) 1**

I'm trying to find similarity of the document set with the user's query applying Vector space modelling. Here goes the code:

```
% docs is a sprase matrix presenting a number of document.
sc=zeros(1, n); doc_inds=zeros(1, n);
% q is the user query.
sc=q'*docs;
%sort documents according to their
similarity coefficient with the query
[sc, doc_inds]=sort(sc);
sc=sc(end:-1:1);doc_inds=doc_inds(end:-1:1);
```

The line `sc=q'*docs;`

always produces error saying: **??? Inner matrix dimensions must** . **agree.**

Can anyone help me getting an idea to deal with it ? Appreciate your time.

According to the data in your example, `docs`

is 5x5 and `q`

is 2x1. The matrix multiplication `q'*docs`

is attempting to multiply a 1x2 matrix with a 5x5 matrix. Matrix multiplication requires that the second dimension of the first matrix agrees with the first dimension of the second matrix, thus the error you are getting.

Why are you defining `sc`

at the line `sc=zeros(1, n);`

and then overwriting it with this matrix multiplication?

Similar Questions

I have a large sparse matrix X in scipy.sparse.csr_matrix format and I would like to multiply this by a numpy array W making use of parallelism. After some research I discovered I need to use Array in

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.

I am examining java version sparse matrix multiplication program which is from JGF benchmark. I run this program in many kinds of cpu frequency. I also do some profile for this program. I classify it

I am looking for a good (in the best case actively maintained) C++ matrix library. Thereby it should be templated, because I want to use a complex of rationals as numerical type. The matrices what I a

I have a sparse matrix: from scipy import sparse a = sparse.diags([1,4,9],[-1,0,1],shape =(10,10),format =csr) I want to take the square root of each of the elements in the sparse matrix I look up

Using the Matrix package I can create a two-dimensional sparse matrix. Can someone suggest a package that would allow me to create a multidimensional (specifically a 3-dimensional) sparse matrix (arra

When trying to directly set the data attribute of a sparse lil_matrix, I encounter very unexpected behavior. Can someone explain what is going on in the following simple example? My particular use ca

I am using a sparse matrix format implemented in scipy as csr_matrix. I have a mat variable which is in csr_matrix format and all its elements are non-negative. However, when I use mat + mat operation

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 matrix x = [0 0 0 1 1 0 5 0 7 0] I need to remove all of the zeros such as x=[1 1 5 7] The matrices I am using are large (1x15000) I need to do this multiple times (5000+) Efficiency is key

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

guys, Rotation matrix is orthogonal matrix. Shearing matrix is orthogonal matrix? Here is a 2D shearing matrix. H(s) = |1 s| |0 1|

I have a large sparse matrix (lil) implemented in Python with scipy, which comprises of Users on one axis, and songs they played on the other. So each row is a linked list of the songs that user has p

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 =

I need a library to solve Ax=b systems, where A is a non-symmetric sparse matrix, with 8 entry per row (and it might be quite big). I think a library that implements biconjugate gradient should be fin

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 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

I have to create a matlab matrix that is much bigger that my phisical memory, and i want to take advantage of the sparsity. This matrix is really really sparse [say N elements in an NxN matrix], and m

I am implementing a sparse matrix class in compressed row format. This means i have a fixed number of rows and each row consists of a number of elements (this number can be different for different row

I have a vector nodenames as nodenames <- c(A,B,C,T,N,Z) I have a square sparse matrix with dimnames as Formal class 'dgCMatrix' [package Matrix] with 6 slots ..@ i : int [1:4149962]

i am attempting to debug a part of the code but getting this error: ??? Error using ==> plus Matrix dimensions must agree. Error in ==> dwtembed at 48 cH1=cH1+k*pn_sequence_h; This is the code

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

I've got a scipy.sparse_matrix A and I want to zero-out a decently-sized fraction of the elements. (In the matrices I'm working with today, A has about 70M entries and I want to zero-out about 700K of

Say I have the following matrix: A = randi(10, [6 3]) 7 10 3 5 5 7 10 5 1 6 5 10 4 9 1 4 10 1 And I would like to extract each 2 rows and put them into the third dimension, so the result would be lik

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 created a compressed sparse matrix, but while accessing to a positive index it complains that the index is negative: import scipy.sparse as sparse B= sparse.csc_matrix((110111213141516, 25)) B[11011

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:

Suppose I have a NxN matrix M (lil_matrix or csr_matrix) from scipy.sparse, and I want to make it (N+1)xN where M_modified[i,j] = M[i,j] for 0 <= i < N (and all j) and M[N,j] = 0 for all j. Basi

So I have this matrix here, and it is of size 13 x 8198. (I have called it 'blah'). This is a sparse matrix, in that, most of its entries are 0. When I do an imagesc(blah), I get the following image:

Good Afternoon, I am trying to do: scipy.sparse.dia_matrx(x, shape = (x.size, x.size)) but the resulting shape of the matrix is x.size x 1. Am i doing something wrong? Or did i miss something in the

I have the following matrix which I believe is sparse. I tried converting to dense using the x.dense format but it never worked. Any suggestions as to how to do this?, thanks. mx=[[(0, 2), (1, 1), (2,

I recently installed Cholmod in order to perform sparse cholesky decompositions in some C++ code. I wanted to then use the decomp to calculate the matrix inverse (I have the following problem: d^T . (

I am using the cusp library with CUDA to use sparse matrix. Can't I use it in a struct in C like: #include <cusp/coo_matrix.h> #include <cusp/multiply.h> #include <cusp/print.h> #in

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

I have a large (500k by 500k), sparse matrix. I would like to get the principle components of it (in fact, even computing just the largest PC would be fine). Randomized PCA works great, except that it

I am very new to the use of sparse matrices for solving simultaneous equations. I want to use them for solving problems in FEA. Is there a FORTRAN routine, or a function in the Intel Math Kernel libra

Is there any sparse matrix library that can do these: solve linear algebraic equations support operations like matrix-matrix/number multiplication/addition/subtraction,matrix transposition, get a row

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

I'm doing a project and I'm doing a lot of matrix computation in it. I'm looking for a smart way to speed up my code. In my project, I'm dealing with a sparse matrix of size 100Mx1M with around 10M n

I'm new to python, coming from matlab. I have a large sparse matrix saved in matlab v7.3 (HDF5) format. I've so far found two ways of loading in the file, using h5py and tables. However operating on t

The problem is: An alternative linked representation for sparse matrices uses nodes that have the fields down, right, roe, col, and value. Each nonzero entry of the sparse matrix is represented by a

I have a sparse matrix A, generated as an output of glmnet function. When I print the matrix A, it shows all the entries and at the top it reads - 1897 x 100 sparse Matrix of class dgCMatrix [[ su

The matrix is so large(size: 100000*100000) which consume two much, so the library should use triplet or other way to store it. I search the Internet, but those library always use common matrix not tr

I've got a SciPy sparse matrix A, let's say in CSR format, and a vector v of matching length. What's the best way of row-scaling A with v, i.e., performing diag(v) * A?

I have a list of 100k items and each item has a list of indices. I am trying to put this into a boolean sparse matrix for vector multiplication. My code isn't running as fast as I would like, so I am

I have a huge sparse matrix (about 500K x 500K entries, with approximately 1% of the values being non-zero. I'm using @mikera's Vectorz library. t is a SparseRowMatrix composed of SparseIndexedVector

I give a small example: matrix A[3*3*2], only 9 elements of matrix A are '1',other elements of A are '0'. (the value of '1' and '0' do not matter, just indicate the number of voxels, and following 5 v

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'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 have a scipy.sparse.dok_matrix (dimensions m x n), wanting to add a flat numpy-array with length m. for col in xrange(n): dense_array = ... dok_matrix[:,col] = dense_array However, this code raises