I have ecommerce data with about 6000 SKUs and 250,000 obs. Simple version below but a lot more sparse. There is only one SKU per line as each line is a transaction. What I have: I want to create a weighted undirected adjacency matrix so that I can do some graph analysis on the market baskets. It would look like

**Advertisement**

# Tag: sparse-matrix

## Import large .tiff file as sparse matrix

I have a large .tiff file (4.4gB, 79530 x 54980 values) with 1 band. Since only 16% of the values are valid, I was thinking it’s better to import the file as sparse matrix, to save RAM. When I first open it as np.array and then transform it into a sparse matrix using csr_matrix(), my kernel already crashes. See code

## How do I construct an incidence matrix from two dataframe columns using scipy.sparse.coo_matrix((data, (i, j)))?

I have a pandas DataFrame containing two columns [‘A’, ‘B’]. Each column is made up of integers. I want to construct a sparse matrix with the following properties: row index is all integers from 0 to …

## score calculation takes too long: avoid for loops – python

I am new to python and I need your kindly help. I have three matrices, in particular: Matrix M (class of the matrix: scipy.sparse.csc.csc_matrix), dimensions: N x C; Matrix G (class of the matrix: …

## Compute sum of power of large sparse matrix

Given a query vector (one-hot-vector) q with size of 50000×1 and a large sparse matrix A with size of 50000 x 50000 and nnz of A is 0.3 billion, I want to compute r=(A + A^2 + … + A^S)q (usually 4 &…

## Trying to make a graph from a sparse matrix: not enough values to unpack (expected 2, got 0)

So I’m trying to make a graph with squares that are colored according to probability densities stored in the 7×7 matrix ‘nprob’. nprob = prob/sum print(nprob.todense()) x,y = np.meshgrid(np.arange(0,…

## Initialize high dimensional sparse matrix

I want to initialize 300,000 x 300,0000 sparse matrix using sklearn, but it requires memory as if it was not sparse: >>> from scipy import sparse >>> sparse.rand(300000,300000,.1) …

## How to convert a PyTorch sparse_coo_tensor into a PyTorch dense tensor?

I create a sparse_coo tensor in PyTorch: import torch # create indices i = torch.tensor([[0, 1, 1], [2, 0, 2]]) # create values v = torch.tensor([3, 4, 5], dtype=torch.float32) # …

## Python matrix multiplication: sparse multiply dense

Given the code snippet: B = A @ M – T where A is a CSR scipy sparse matrix, M and T are two numpy arrays. Question: During the matrix operations, does numpy treat A as a dense matrix, or M and T as …

## Why is ‘scipy.sparse.linalg.spilu’ less efficient than ‘scipy.linalg.lu’ for sparse matrix?

I posted this question on https://scicomp.stackexchange.com, but received no attention. As long as I get answer in one of them, I will inform in the other. I have a matrix B which is sparse and try to utilize a function scipy.sparse.linalg.spilu specialized for sparse matrix to factorize B. Could you please explain why this function […]

**Advertisement**