sparse-matrix

Multiply scipy sparse matrix with a 3d numpy array

Multiply scipy sparse matrix with a 3d numpy array Question: I have the following matrices a = sp.random(150, 150) x = np.random.normal(0, 1, size=(150, 20)) and I would basically like to implement the following formula I can calculate the inner difference like this diff = (x[:, None, :] – x[None, :, :]) ** 2 diff.shape …

Total answers: 2

How do I calculate the matrix exponential of a sparse matrix?

How do I calculate the matrix exponential of a sparse matrix? Question: I’m trying to find the matrix exponential of a sparse matrix: import numpy as np b = np.array([[1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, …

Total answers: 1

Apply slicing, conditionals to Sparse Arrays with Pallalization in Python

Apply slicing, conditionals to Sparse Arrays with Pallalization in Python Question: Apply slicing, conditionals to Sparse Arrays with Pallalization I want to do something like dynamic programming on sparse array. could you check the following example function,which I would like to implement for Sparse Array (the first example is for numpy.array) First,importing modules from numba …

Total answers: 1

Memory efficient dot product between a sparse matrix and a non-sparse numpy matrix

Memory efficient dot product between a sparse matrix and a non-sparse numpy matrix Question: I have gone through similar questions that has been asked before (for example [1] [2]). However, none of them completely relevant for my problem. I am trying to calculate a dot product between two large matrices and I have some memory …

Total answers: 3

How to sum specific row values together in Sparse COO matrix to reshape matrix

How to sum specific row values together in Sparse COO matrix to reshape matrix Question: I have a sparse coo matrix built in python using the scipy library. An example data set looks something like this: >>> v.toarray() array([[1, 0, 2, 4], [0, 0, 3, 1], [4, 5, 6, 9]]) I would like to add …

Total answers: 2

pandas – creating new rows of combination with value of 0

pandas – creating new rows of combination with value of 0 Question: I have a pandas dataframe like user_id music_id has_rating A a 1 B b 1 and I would like to automatically add new rows for each of user_id & music_id for those users haven’t rated, like user_id music_id has_rating A a 1 A …

Total answers: 2

pandas – create sparse matrix for collaborative filtering

pandas – create sparse matrix for collaborative filtering Question: I have a pandas dataframe like this: user_id music_id rating A a 5 B a 3 and I would like to create a sparse matrix from it, putting music_id as column and user_id as a row like this: -> a b A 5 B 3 what …

Total answers: 1

Python correspondent for MATLAB matrix operation

Python correspondent for MATLAB matrix operation Question: I have a vector of indices (let’s call it peo), a sparse matrix P and a matrix W. In MATLAB I can do an operation of this kind: P(peo, peo) = W(peo, peo) Is there a way to do the same in Python maintaining the same computational and …

Total answers: 1

data set convert to matrix with tupel

data set convert to matrix with tupel Question: I need to convert a part of my data to make it compatible with this solution: https://stackoverflow.com/a/64854873 The data is a pandas.core.frame.DataFrame with: result data_1 data_2 1 1.523 4 1223 3 1.33 84 1534 Some index values might be removed, therefore 1, 3, … It should be …

Total answers: 3

How to find the indices of columns that are not entirely zeros of a sparse matrix

How to find the indices of columns that are not entirely zeros of a sparse matrix Question: I have a large sparse array (Python csr). How can I find the indices of columns that are not entirely zeros? For example, if the matrix looks like s constructed below In [13]: import scipy.sparse as sparse In …

Total answers: 2