I have several 2D numpy arrays (matrix) and for each one I would like to convert it to vector containing the values of the array and a vector containing each row/column index.>
You can try this using itertools
import itertools
import numpy as np
import pandas as pd
def convert2dataframe(array):
a, b = array.shape
x, y = zip(*list(itertools.product(range(a), range(b))))
df = pd.DataFrame(data={'V':array.ravel(), 'x':x, 'y':y})
return df
This works for arrays of any shape, not necessarily square matrices.