I am trying to select sparse matrix elements row-wise based on BFS output array. Suppose my BFS output is
[1, 2, 3, 6, 4, 7, 5, 8, 11, 9, 12, 10, 13, 15, 14, 16, 17, 18, 19, 20]
and I have a sparse matrix of 20x20 for example.
Now I want to use BFS output as row index and select nonzero values from the sparse matrix in same order as that of BFS output array and plot. Here is my code through which I can do some job but not perfectly what I wanted.
a = numpy.loadtxt('sparsematrix.txt', float, delimiter=',') # import data
y = numpy.reshape(a, np.size(a))
pos = np.delete(y, np.arange(0, y.size, 19))
plt.plot(pos)
plt.xlabel(sample)
plt.ylabel(position)
Problem with the above code is:
- It selects every value in row-wise, but not in defined order of my BFS output. (it should use BFS output array as row index number to select nonzero values one-by-one)
- It selects all the values, even zeros. - How to get only nonzero values?
- Indexing is starting from 0 and goes to 19. I want indexing to start from 1 onwards.