Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33210

Re: Division matrix

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'rewrite': 0.07; 'val': 0.07; 'calculates': 0.09; 'compute': 0.09; 'len(x)': 0.09; 'loop.': 0.09; 'def': 0.10; ';-)': 0.11; 'exercise': 0.13; 'passing': 0.15; "'c'": 0.16; '6:00': 0.16; '[2,': 0.16; 'after,': 0.16; 'inverse': 0.16; 'with?': 0.16; 'x.append(y)': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'math': 0.20; 'variable': 0.20; 'written': 0.20; 'help.': 0.22; 'defined': 0.22; 'mention': 0.23; "haven't": 0.23; 'header:In-Reply-To:1': 0.25; 'leave': 0.26; 'message-id:@mail.gmail.com': 0.27; 'dimensions': 0.29; 'index,': 0.29; 'probably': 0.29; 'this.': 0.29; 'that.': 0.30; 'up.': 0.31; 'code': 0.31; 'generally': 0.32; 'could': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'really': 0.36; 'but': 0.36; 'wanted': 0.36; '12,': 0.36; "i'll": 0.36; 'should': 0.36; 'thank': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'your': 0.60; 'you.': 0.61; 'first': 0.61; 'solve': 0.62; 'details': 0.63; 'more': 0.63; 'await': 0.75; 'exercise.': 0.84; 'matrix.': 0.84; 'multiply': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=7kZpif3w2cXtzoa0mIARFfJpiP9qb3y7Y7EE/j3NWpQ=; b=ZoRsHxTOIJz7BQocBDu9ISYpgBD+yZheaPmmC2QIgDHW+RDMJx75Kd2BU3XMNpZlMu vr/0wKJlwSNvL8zdAbdG351maULk0jdCR6ELSJ8uUEOd6LBbRHjaWmzWQtHyzTT2Imvm KGaWITKSieMFcF6vk6tss04MGET5Y65uoWrGWsmhweDJXMrchc6wlQi/2Auni1F5cTkj JImWA0A9C/KRJ6g9v84achIpwWI79WwwPg5KiGm4I79W6Vk69d6OmPkEJHiJIdMVzaOE MIc9ntuxqwhugvi6dKtyi6NOcLWI415zrBMTP60n5AB29h+A+QkXjmfIWUOcdryK4Y91 c1hQ==
MIME-Version 1.0
In-Reply-To <98b451e1-5cd5-46e9-8be4-59dcc835700b@googlegroups.com>
References <98b451e1-5cd5-46e9-8be4-59dcc835700b@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 12 Nov 2012 18:25:33 -0700
Subject Re: Division matrix
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3601.1352769970.27098.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352769970 news.xs4all.nl 6962 [2001:888:2000:d::a6]:54867
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33210

Show key headers only | View raw


On Mon, Nov 12, 2012 at 6:00 PM, Cleuson Alves <cleuson.o@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Division matrix Cleuson Alves <cleuson.o@gmail.com> - 2012-11-12 17:00 -0800
  Re: Division matrix Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-12 18:25 -0700
  Re: Division matrix Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-13 13:48 -0500
  Re: Division matrix "R. Michael Weylandt" <michael.weylandt@gmail.com> - 2012-11-13 22:14 +0000
  Re: Division matrix wxjmfauth@gmail.com - 2012-11-14 01:04 -0800

csiph-web