I have a matrix of size nn and I have a list containing specific nodes in the graph in each iteration I have to remove the specific row and corresponding column based on the value in the list, how do I can know the specific row and column since the size of the matrix decreasing.
for example, I have the following 44 matrix
L=[8 -1 -1 0; -1 6 -1 0; -1 -1 5 0; 0 0 0 7]
if the list is the following a=[2,3]
so I have to delete the second row and column the matrix will be L=[8 -1 0; -1 5 0; 0 0 7]
now I have to delete the third row and column in the original matrix which is the second one now, I want a general way to use it even with huge matrices and I have to do it one by one because I know it’s possible do it all by once, I am using the following function for deleting
Do you really need to delete them? Deleting a row or a column of a matrix can be very slow. One way to avoid really deleting it could be:
A = rand(10,10)
i,j = trues(10), trues(10)
i = false; j = false #to remove 3rd row and 4th column
B = @view A[i,j] # B is an AstractMatrix
i = false
C = @view A[i,j] # C has also row 7 deleted etc
If you really need to delete them, you could do A = A[i,j]
This would return a non-contiguous view, which is possible, but could have very negative performance consequences when you want to use the view. Contiguous or regularly spaced views are better than irregular ones like this.
Thank you so much, but what you mentioned is the way of deleting the rows all at once, my problem is actually after deleting one row and column the indices of the rows and columns in the new matrix and all I need is a way to get the right indecies after each delete
Honestly, it sounds like a matrix may be a poor choice of data structure for the types of operations you want to perform. If you give a little more information about the algorithm you are trying to implement, we might be able to suggest a better data structure.
I have the following code where I am trying to calculate the smallest eigenvalue of the laplacian matrix, for that, I sort the nodes of the graph based on their degrees and start deleting the corresponding row and column for each node and check the value after each delete, the problem that when I start deleting the indices changed as I explained before so I need a way to get the right index after each delete, here is the code
G=loadgraph("mexican.graphml", "G" , GraphIO.GraphML.GraphMLFormat())
min_deg = sortperm(degree(G))
L = L[1:end .!= min_deg, 1:end .!= min_deg]
min_eign = eigen_values
for i in 2:nv(G)
if min_eign >= first_eigen && size(L) > 3
first_eigen = eigen_values
if min_deg[i] > size(L)
L = L[1:end .!= size(L), 1:end .!= size(L)]
L = L[1:end .!= min_deg[i], 1:end .!= min_deg[i]]
Without making any consideration on the suitability of the thought structure, I propose an idea to obtain the indices as desired by the OP.
The implementation changes if, by any chance, the indexes to be used are sorted, for example, in ascending order.
for i in eachindex(a)
for i in eachindex(a)
thank you so much, but unfortunately I don’t have the option of sorting the indices because it represents something as it is other than that the solution you proposed is totally fine by I need it without changing anything on the list of indices