sparse-matrix

Sparse Matrix Assignment becomes very slow in Matlab

泄露秘密 提交于 2019-12-02 01:24:28
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',',','EmptyValue', 0); line_number = line_number+1; P(line_number,:)=C{1}; end the problem I have is that while at the beginning the P(line_number,:)=C{1}; statement is fast, after a few thousands lines become exterely slow, I guess because Matlab need to find the memory space to allocate every time. Is there a way to pre-allocate memory with sparse matrixes? I don't think so but maybe I am missing something.

Solving an underdetermined scipy.sparse matrix using svd

北城以北 提交于 2019-12-02 00:35:50
问题 Problem I have a set of equations with variables denoted with lowercase variables and constants with uppercase variables as such A = a + b B = c + d C = a + b + c + d + e I'm provided the information as to the structure of these equations in a pandas DataFrame with two columns: Constants and Variables E.g. df = pd.DataFrame([['A','a'],['A','b'],['B','c'],['B','d'],['C','a'],['C','b'], ['C','c'],['C','d'],['C','e']],columns=['Constants','Variables']) I then convert this to a sparse CSC matrix

Is sparse BLAS not included in BLAS?

瘦欲@ 提交于 2019-12-02 00:09:41
I have a working LAPACK implementation and that, as far as I read, contains BLAS. I want to use SPARSE BLAS and as far as I understand this website , SPARSE BLAS is part of BLAS. But when I tried to run the code below from the sparse blas manual using g++ -o sparse.x sparse_blas_example.c -L/usr/local/lib -lblas && ./sparse_ex.x the compiler (or linker?) asked for blas_sparse.h. When I put that file in the working directory I got: ludi@ludi-M17xR4:~/Desktop/tests$ g++ -o sparse.x sparse_blas_example.c -L/usr/local/lib -lblas && ./sparse_ex.x In file included from sparse_blas_example.c:3:0:

Solving an underdetermined scipy.sparse matrix using svd

倾然丶 夕夏残阳落幕 提交于 2019-12-01 20:45:36
Problem I have a set of equations with variables denoted with lowercase variables and constants with uppercase variables as such A = a + b B = c + d C = a + b + c + d + e I'm provided the information as to the structure of these equations in a pandas DataFrame with two columns: Constants and Variables E.g. df = pd.DataFrame([['A','a'],['A','b'],['B','c'],['B','d'],['C','a'],['C','b'], ['C','c'],['C','d'],['C','e']],columns=['Constants','Variables']) I then convert this to a sparse CSC matrix by using NetworkX table = nx.bipartite.biadjacency_matrix(nx.from_pandas_dataframe(df,'Constants',

Matlab sparse tensor

ぐ巨炮叔叔 提交于 2019-12-01 18:17:58
Does Matlab support efficient operations on large sparse tensors? More specifically: Is there an elegant way, similar to sparse , of loading and storing a sparse tensor? As far as I can understand, sparse can only load matrices. Are operations like tensor product implemented efficiently over sparse tensors? I realize I can always store a tensor as a combination of cell arrays of matrices, but that would require using loops, and I'm hoping to avoid that. Since the data I'm working with is very large, I cannot consider a non-sparse representation. Out of the box, I believe MATLAB only handles

Matlab sparse tensor

假如想象 提交于 2019-12-01 17:26:04
问题 Does Matlab support efficient operations on large sparse tensors? More specifically: Is there an elegant way, similar to sparse , of loading and storing a sparse tensor? As far as I can understand, sparse can only load matrices. Are operations like tensor product implemented efficiently over sparse tensors? I realize I can always store a tensor as a combination of cell arrays of matrices, but that would require using loops, and I'm hoping to avoid that. Since the data I'm working with is very

why is row indexing of scipy csr matrices slower compared to numpy arrays

断了今生、忘了曾经 提交于 2019-12-01 13:47:15
I'm not sure what I am doing wrong but it seems that row indexing a scipy csr_matrix is approximately 2 folds slower compared to numpy arrays (see code below). Shouldn't row indexing of csr matrices be faster than dense matrices because only few non-zero elements are extracted like in the case below ? Are there tricks to make row indexing faster for scipy csr matrices ? import numpy as np import timeit from scipy.sparse import csr_matrix # Generate random matrix A = np.random.rand(5000, 1000) # Make A sparse A[:, 4:] =0 # Create sparse matrix A_sparse = csr_matrix(A) # Create row indexing

MATLAB - efficient way of computing distances between points in a graph/network using the adjacency matrix and coordinates

狂风中的少年 提交于 2019-12-01 12:32:41
I have the network representation in a 2D coordinate space. I have an adjacency matrix Adj (which is sparse) and a coordinate matrix with the x,y values of all the points/nodes/vertices in the graph which are drawn. I would like to compute as efficiently as possible the distance between these points. I would like to avoid cycling through the entries in the matrix and computing the pairwise distances one by one. [n, d] = size(coordinate); assert(d == 2); resi = sparse(Adj * diag(1:n)); resj = sparse(diag(1:n) * Adj); res = sparse(zeros(n)); f = find(Adj) res(f) = sqrt((coordinate(resi(f), 1) -

Matlab uint8 sparse

牧云@^-^@ 提交于 2019-12-01 10:11:14
When creating a sparse matrix in Matlab it seems that you can create a sparse matrix either filled with logicals or double valued numbers. While reading around I understood that Matlab does not have support for other type of sparse matrices, i.e. uint8 or other integers. In my application I know that max(values)==16 , and the memory is a crucial thing, therefore I would like to have uint8 sparse matrices. Is there a way of creating a unit8 sparse matrix? If not (most likely), is there any apparent reason of why Matlab has not implemented uint8 sparse matrices? I can see how using uint8 instead

Python: how to use Python to generate a random sparse symmetric matrix?

风格不统一 提交于 2019-12-01 09:34:04
问题 How to use python to generate a random sparse symmetric matrix ? In MATLAB, we have a function "sprandsym (size, density)" But how to do that in Python? 回答1: If you have scipy, you could use sparse.random. The sprandsym function below generates a sparse random matrix X, takes its upper triangular half, and adds its transpose to itself to form a symmetric matrix. Since this doubles the diagonal values, the diagonals are subtracted once. The non-zero values are normally distributed with mean 0