The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Division matrix
 There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standard view   View as tree
 4 messages

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Nov 12 2012, 8:00 pm
Newsgroups: comp.lang.python
From: Cleuson Alves <cleuso...@gmail.com>
Date: Mon, 12 Nov 2012 17:00:27 -0800 (PST)
Local: Mon, Nov 12 2012 8:00 pm
Subject: Division matrix
Hello, I need to solve an exercise follows, first calculate the inverse matrix and then multiply the first matrix.
I await help.
Thank you.
follows the code below incomplete.

m = [[1,2,3],[4,5,6],[7,8,9]]
x = []
for i in [0,1,2]:
y = []
for linha in m:
y.append(linha[i])
x.append(y)

print x
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]

def ProdMatrix(x,b):
tamL = len(x)
tamC = len(x[0])
c = nullMatrix(tamL,tamC)
for i in range(tamL):
for j in range(tamC):
val = 0
for k in range(len(b)):
val = val + x[i][l]*b[k][j]
c[i][j]
return c

To post a message you must first join this group.
You do not have the permission required to post.
More options Nov 12 2012, 8:26 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Mon, 12 Nov 2012 18:25:33 -0700
Local: Mon, Nov 12 2012 8:25 pm
Subject: Re: Division matrix

On Mon, Nov 12, 2012 at 6:00 PM, Cleuson Alves <cleuso...@gmail.com> wrote:
> Hello, I need to solve an exercise follows, first calculate the inverse matrix and then multiply the first matrix.
> I await help.
> Thank you.
> follows the code below incomplete.

So what is the specific problem with the code that you're looking for help with?

> m = [[1,2,3],[4,5,6],[7,8,9]]
> x = []
> for i in [0,1,2]:
>     y = []
>     for linha in m:
>         y.append(linha[i])
>     x.append(y)

> print x
> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

This calculates the transpose of the matrix, not the inverse.  If the
inverse is really what you're after, you should start by reading up on
the math to compute that.

Note that "for i in [0,1,2]:" could be more generally written as "for
i in range(len(m[0])):", and then you don't need to rewrite your for
loop if the dimensions of m change.

If you actually do want the transpose, then I'll also mention in
passing that there is a very nice one-liner using zip() to do this.
I'll leave the details as an exercise. ;-)

> def ProdMatrix(x,b):
>     tamL = len(x)
>     tamC = len(x[0])
>     c = nullMatrix(tamL,tamC)
>     for i in range(tamL):
>         for j in range(tamC):
>             val = 0
>             for k in range(len(b)):
>                 val = val + x[i][l]*b[k][j]
>             c[i][j]
>     return c

In the multiplication line you're using the variable 'l' as an index,
but you haven't defined it.  Probably you wanted 'k' here.

You're also discarding 'val' after adding it up.  If you want that
value in the 'c' matrix, then you need to store it there before going
on to the next loop.

To post a message you must first join this group.
You do not have the permission required to post.
More options Nov 13 2012, 5:15 pm
Newsgroups: comp.lang.python
From: "R. Michael Weylandt" <michael.weyla...@gmail.com>
Date: Tue, 13 Nov 2012 22:14:32 +0000
Local: Tues, Nov 13 2012 5:14 pm
Subject: Re: Division matrix

On Tue, Nov 13, 2012 at 1:00 AM, Cleuson Alves <cleuso...@gmail.com> wrote:
> Hello, I need to solve an exercise follows, first calculate the inverse matrix and then multiply the first matrix.

I would just point out that in most numerical applications, you rarely
need to calculate the intermediate of the matrix inverse directly.
See, e.g., http://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/

Of course, if this hasn't been said yet: NumPy.

Michael

To post a message you must first join this group.
You do not have the permission required to post.
More options Nov 14 2012, 4:04 am
Newsgroups: comp.lang.python
From: wxjmfa...@gmail.com
Date: Wed, 14 Nov 2012 01:04:09 -0800 (PST)
Local: Wed, Nov 14 2012 4:04 am
Subject: Re: Division matrix
Le mardi 13 novembre 2012 02:00:28 UTC+1, Cleuson Alves a écrit :

------

Pedagogical hint:
Before blindly calculating the inverse matrix, it may be
a good idea to know if the inverse matrix exists.

jmf