Division matrix

2012-11-12 Thread Cleuson Alves
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Division matrix

2012-11-13 Thread Cleuson Alves
Thanks, I'm starting to plan now, so I'm still confused with the production
code, but what I need is to divide array 2x2 or 3x3.
I still can not!



2012/11/12 Joshua Landau 

> On 13 November 2012 01:00, Cleuson Alves  wrote:
>
>> Hello, I need to solve an exercise follows, first calculate the inverse
>> matrix and then multiply the first matrix.
>>
>
> This list isn't to give answers for homeworks, and this sounds like one.
> We *do* give help to those who have a specific problem and who preferably
> show that they are trying to help up help them.
>
>
>> I await help.
>>
>
> For what?! You haven't asked a question.
> 1) What do you need. Answer precisely, preferably giving an example output
> for the input you want
> 2) What techniques have you tried? You have given code below in an
> extremely un-obvious manner. What does it do, crash? Is it the wrong
> output? What is wrong about the output?
> 3) What do you *think* has gone wrong? What about the output seems to be
> wrong?
>
>
>> Thank you.
>> follows the code below incomplete.
>>
>
> On the basis that we can get some foreign people who maybe don't have
> English as a commonly used language, muddled grammar isn't that big deal.
> However, when asking for help it is worth checking that you've asked in a
> clear way.
>
>
>> 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]]
>>
>
> Is this the right output? Is this what you *meant* by inverse? As Ian
> Kelly (who is undoubtedly more learned in this area) said, this is a
> transpose, so you have just swapped the one axis with another.
>
>
>> 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
>>
>
> You haven't given the full code. This crashes because we don't have
> "nullMatrix" defined. It would be nice if we had something we could try to
> run.
>
> Then, the error is: "NameError: global name 'l' is not defined". On the
> line "val = val + x[i][l]*b[k][j]" you use a variable "l" which doesn't
> exist. What should you be using, or should you have created it?
>
> *Then* you get an output of pure 0s. This is because you forgot to put
> your result into c, your new matrix.
> You probably just forgot to finish the line "c[i][j]", which does nothing
> now.
>
> You're actually really close on the second part. I have no idea if you're
> doing what you want for the first part, but it's not what's traditionally
> called an inverse.
>



-- 
Cleuson de Oliveira Alves
Rio de Janeiro - RJ
-- 
http://mail.python.org/mailman/listinfo/python-list


Logwatch python

2013-02-09 Thread Cleuson Alves
Hello, I am trying to run this code, but I get an answer incorrect arguments 
numbers. someone could put an example of arguments for me to use in the / var / 
log?

Thank you.



import os, sys
from optparse import OptionParser

def main():
usage = "%prog [options] args"
parser = OptionParser(usage)
parser.add_option("-l", "--logfile", dest="logfile", help="Logfile to read 
data")
parser.add_option("-p", "--logpos", dest="logpos", help="File to store last 
log line read position")
parser.add_option("-f", "--find", dest="findstring", help="String to find 
in Logfile")
(options, args) = parser.parse_args()
if options.logfile is None or options.findstring is None or options.logpos 
is None:
print("Incorrect arguments numbers.\n")
parser.print_help()
sys.exit(-1)
else:
logfile = options.logfile
tofind = options.findstring
logpos = options.logpos

pos = 0
count = 0
if os.path.isfile(logpos):
pos = int(open(logpos).readline() or 0)
file = open(logfile)
file.seek(pos)
for line in file:
if line.find(tofind) != -1:
count += 1
pos = file.tell()
file.close()
file = open(logpos, 'w')
file.write(str(pos))
file.close()
print count

if __name__ == '__main__':

main()
-- 
http://mail.python.org/mailman/listinfo/python-list