Home>
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 ith and jth 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 nonzero 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
Related articles
 python  what is the difference between the two jupyter kernels generated by conda?
 python  regarding the difference between 127001 and localhost
 python  about the difference in behavior between sort and sorted
 python 3x  difference between your own code and the correct code
 python 3x  i want to create a graph showing the slope of each point of a curve in python
 i want to create a for statement to output the day of the week in python
 python 3x  exchange of values between classes
 python  about visibledeprecationwarning (why is it deprecated to create an ndarray object from a jug array?)
 python  i want to create a discordpy eval command
 [python] assigning a column vector to a matrix
 i want to automatically create an excel quote with python
 python  i want to calculate matrix calculation with numpy for statement with numpydot
 i want to create a function to judge python prime numbers and display 15 prime numbers of integer n or more
 i want to create an additional excel sheet with python and add it
 [python] i want to calculate an excel matrix with a for statement
 python  i can't create a virtual environment with pipenv
 c #  what is the difference between readblockasync and readasync in streamreader?
 python  [xlwings] i want to copy the entire selection of a matrix containing values and paste it into the specified cell
 python  logic to create multiple combinations from multiple values so that the total is 1000 or more
 [python] i want to calculate a matrix with a strange law
Related questions
 python  issue a bullet with the bind method (game program)
 python  while syntax processing
 python  about openpyxl error avoidance
 error display on python discord bot
 python  it takes too much time to do with big data with many for
 python  psycopg2 cannot be read by pycharm
 python  i got an error in opencv
 only part of the data is recognized when learning python
 python  i want to convert the characters obtained from the txt file to numbers
 python  discord teaming bot doesn't work properly