Hi @iffiX, really sorry to bother you but would be great if I could get your input on one more question.
If I were to follow the code that you had suggested, where every row vector (of the dataset, or more specifically of  X_prime ) is converted to a matrix (ie. a density) and then these matrices are all put into the one tensor object, I think this will run into memory blow-out issues. For eg., if my dataset has say 200,000 rows, then I will have 200,000 matrices that needs to be stored at one time, and this could cause a memory blow-out.
In comparison, the code that I have calculates the running sum of the matrices/densities at every step when a new row vector is converted to a matrix, therefore I do not need to store all the matrices in one tensor object (and then only sum them all up after).
Just wanted to get your thoughts on this. It’s ok too if you’re unsure.
Many thanks once again.