Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Inverse of singular matrix Divanova94 Programmer named Tim Posts: 8 Threads: 2 Joined: Apr 2019 Reputation: 0 Likes received: 0 #1 May-04-2019, 10:12 AM How one can invert this singular matrix? ```m1 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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[0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0] [1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]] `````` scidam Posts: 422 Threads: 0 Joined: Mar 2018 Reputation: 59 Likes received: 61 #2 May-04-2019, 10:42 AM This matrix is of shape (30, 20). Therefore, it couldn't be inverted in traditional sense. The main question here is why do you need to invert such matrix? May be you need to solve a system of linear equation with that matrix, e.g. `Ax = b`. In this case, your system is probably overdetermined and has no solution in classical sense, but it could be solved in least squares sense. Even if the matrix has insufficient rank, e.g. `rank(A) < 20`, you can obtain least squares solution using Moore-Penrose inversion. It is implemented in `numpy`: `np.linalg.pinv`. So, least squares solution could be obtained as follows: `x = np.linalg.pinv(A) @ b`, where b is known vector of shape `(30, 1)`; you can use `np.dot(np.linalg.pinv(A), b)` instead of `@` (if you work with Py < 3.5). Gribouillis likes this post Divanova94 Programmer named Tim Posts: 8 Threads: 2 Joined: Apr 2019 Reputation: 0 Likes received: 0 #3 May-04-2019, 10:51 AM (May-04-2019, 10:42 AM)scidam Wrote: This matrix is of shape (30, 20). Therefore, it couldn't be inverted in traditional sense. The main question here is why do you need to invert such matrix? May be you need to solve a system of linear equation with that matrix, e.g. `Ax = b`. In this case, your system is probably overdetermined and has no solution in classical sense, but it could be solved in least squares sense. Even if the matrix has insufficient rank, e.g. `rank(A) < 20`, you can obtain least squares solution using Moore-Penrose inversion. It is implemented in `numpy`: `np.linalg.pinv`. So, least squares solution could be obtained as follows: `x = np.linalg.pinv(A) @ b`, where b is known vector of shape `(30, 1)`; you can use `np.dot(np.linalg.pinv(A), b)` instead of `@` (if you work with Py < 3.5). Yes I need to solve a system of linear equation, and I tried with Moore-Penrose inversion, but the solution it is not sufficient. Therefore I am looking for another was of inverting this matrix. scidam Posts: 422 Threads: 0 Joined: Mar 2018 Reputation: 59 Likes received: 61 #4 May-05-2019, 11:19 AM (This post was last modified: May-05-2019, 11:19 AM by scidam. Edited 1 time in total.) Pseudoinverse gives you a solution of minimum norm; In your case matrix A has rank=15, so you have "quite large subspace of freedom" to choose another solution. From the following post you can find how to get any solution: `any_solution = np.linalg.pinv(A) @ b + (np.ones((20, 20)) - np.linalg.pinv(A)@A)@ y # y.shape = (20, 1)``y` is arbitrary vector. Choosing appropriate `y` probably lead you to desirable solution. scidam Posts: 422 Threads: 0 Joined: Mar 2018 Reputation: 59 Likes received: 61 #5 May-11-2019, 02:40 AM I made a mistake in my previous post, `np.ones(...)` should be replaced with `np.eye(20)`. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post comparing each rows of two matrix PhysChem 10 923 May-17-2019, 06:50 AM Last Post: Gribouillis matrix by vector mcgrim 8 289 May-02-2019, 10:39 AM Last Post: ichabod801 Extract of matrix subpart using a deep copy paul18fr 2 183 May-02-2019, 06:49 AM Last Post: paul18fr Help in adding confusion matrix Aashish 5 489 Apr-15-2019, 11:45 PM Last Post: scidam counting the occurence of a specified number in a numpy-matrix PhysChem 1 217 Apr-03-2019, 01:37 PM Last Post: PhysChem function matrix mcgrim 14 684 Mar-19-2019, 09:28 PM Last Post: mcgrim PyCM 1.8 released: Machine learning library for confusion matrix statistical analysis sepandhaghighi 0 299 Jan-05-2019, 12:36 PM Last Post: sepandhaghighi Creating matrix counting words in list of strings jazmad 2 433 Dec-23-2018, 05:47 PM Last Post: jazmad Clustering based on a variable and on a distance matrix flucoe 2 571 Dec-16-2018, 09:57 PM Last Post: flucoe The twelfth root of a matrix Arduinol 9 707 Nov-28-2018, 11:36 AM Last Post: Gribouillis

Forum Jump:

Users browsing this thread: 1 Guest(s)