I want to create a matrix where the element number (i, j) that is not 0 of the large sparse matrix is the difference between the i-th and j-th vectors.
# A is a sparse matrix #the dimension of A is 1000000 × 1000000 rows, cols = A.nonzero () index = [(i, j) for i, j in zip (rows, cols)] Set of non-zero element numbers print (len (index)) # 5000000 B = A.copy () #y is a vector #the dimension of y is 1000000 for i, j in index: B [i, j] = y [i]-y [j]
You can actually create a matrix.
However, as shown above, a large matrix is used. Therefore, it takes a long time to execute.
I think this is because the execution speed of the for statement is slow in python.
Tell me if there is a way to do it faster.
Answer # 1
import scipy.sparse rows, cols = A.nonzero () data = y [rows] -y [cols] B = sparse.coo_matrix ((data, (rows, cols)))
- python - difference between pandas dataframeplotbar and dataframeplot (kind = bar)
- what is the difference between environment variables in python and environment variables that can be seen in system-> system
- python - what is the difference between the two jupyter kernels generated by conda?
- python 3x - difference between your own code and the correct code
- i want to get an array of directory names and file names in python and create a csv
- [python] i want to draw the error between two graphs and cos (x)
- do beginners learn golang? → (change) i want to create a web application with python and automate troublesome things
- i want to create a function in python that all functions without class go through
- unity - difference between camera coordinates and visible position
- ruby on rails 5 - i don't understand the difference between model and controller methods
- how to create a qr code in python and paste it directly into word
- i want to create a function that calculates the absolute value in python
- python - confusion matrix display in image recognition on cnn
- php calculate the difference between the elements of a two-dimensional array
- python - create a program to automatically take a screenshot of the kindle screen and save it
- what is the difference between a middleware ap server and an application?
- python - find the matrix || v || 2 (2-norm)
- python - tabelog scraping: i want to create a data frame for each store name, address, and evaluation score