Jan-20-2022, 11:58 PM
(Jan-20-2022, 06:24 PM)deanhystad Wrote: I think you are way down the rabbit hole of "How do I do this" when I have serious doubts that this is something you need to do. Why do you have 64 rho variables instead of a rho list? If you had a rho list you could reshape it to fit your needs.
Of course I had to give it a try since it looks like a fun problem.
class RefMatrix(): def __init__(self, ref): self.ref = ref self.indices = [] self.rows = len(ref) self.columns = len(ref[0]) self._values = [] for r in range(self.rows): self.indices.append([(r, c) for c in range(self.columns)]) self._values.append([0]*self.columns) def values(self): for r, row in enumerate(self.indices): for c, index in enumerate(row): self._values[r][c] = self.ref[index[0]][index[1]] return self._values def swapRows(self, a, b): self.indices[a], self.indices[b] = self.indices[b], self.indices[a] return self def swapColumns(self, a, b): for row in self.indices: row[a], row[b] = row[b], row[a] return self data = [[r*4+c for c in range(4)] for r in range(4)] ref = RefMatrix(data).swapRows(2, 3).swapColumns(2, 3) print(data) print(ref.values())
Output:[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] [[0, 1, 3, 2], [4, 5, 7, 6], [12, 13, 15, 14], [8, 9, 11, 10]]
thanks for answer,
will also try this way after make other way run correctly. but the main point I am multiplying this rho symbolic matrices with other real matrices. This is why I had to use sympy. Otherwise, it is not possible to multiply a real matrix with a symbolic matrix