Python Forum
Write the Matrix2 by using Matrix1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write the Matrix2 by using Matrix1
#15
(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
Reply


Messages In This Thread
Write the Matrix2 by using Matrix1 - by quest - Jan-19-2022, 12:20 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-19-2022, 11:43 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 08:20 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:37 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:54 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 12:29 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:18 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-20-2022, 11:58 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-22-2022, 12:41 AM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-23-2022, 11:57 PM
RE: Write the Matrix2 by using Matrix1 - by quest - Jan-24-2022, 01:07 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020