wxPython mnożenie macierzy

0

Witam robię właśnie skromy projekt w pythonie i nie mogę pomnożyć macierzy może ktoś mnie naprowadzić na dobry trop ? :)

import wx
from pylab import*
class App(wx.App):

    def OnInit(self):
       frame = MainFrame()
       frame.Show()
       self.SetTopWindow(frame)
       return True
class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,title='Projekt MN',size=(300,300))

        panel=wx.Panel(self)


        bmp2 = wx.Image("OFF.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.button1 = wx.BitmapButton(panel, -1, bmp2, pos=(0, 10),size=(48,48))

        self.Bind(wx.EVT_BUTTON,self.closebutton,self.button1)


        bmp = wx.Image("matrix.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.button2 = wx.BitmapButton(panel, -1, bmp, pos=(0, 60))

        self.Bind(wx.EVT_BUTTON,self.macierz,self.button2)

        bmp3 = wx.Image("panel.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.button3 = wx.BitmapButton(panel, -1, bmp3, pos=(0, 120))
        self.Bind(wx.EVT_BUTTON,self.panel,self.button3)

        self.printArea=wx.TextCtrl(panel,pos=(80,20),size=(100,100),style=wx.BORDER_SUNKEN)





    def closebutton(self,event):
        self.Close(True)

    def closewindow(self,event):
        self.Destroy()
    def macierz(self,event):
        dial=wx.MessageDialog(None,'Lolek','Na co sie patrzysz',wx.OK | wx.ICON_INFORMATION)


        def arr(n):
            array=[]
            for i in range (0,n):
                array.append(0)
            return array
        tablica=arr(5)
        self.printArea.SetValue(str(tablica))

    def panel(self, event):
        AboutFrame().Show()


class AboutFrame(wx.Frame):

    title = "Licz macierz !"

    def __init__(self):
        wx.Frame.__init__(self, wx.GetApp().TopWindow, title=self.title)
        panel=wx.Panel(self)


        bmp2 = wx.Image("OFF.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        self.button1 = wx.BitmapButton(panel, -1, bmp2, pos=(10, 150),size=(48,48))
        self.Bind(wx.EVT_BUTTON,self.show,self.button1)


        self.PrintAreaa1=wx.TextCtrl(panel,pos=(10, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreaa2=wx.TextCtrl(panel,pos=(70, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreaa3=wx.TextCtrl(panel,pos=(130, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreab1=wx.TextCtrl(panel,pos=(10, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreab2=wx.TextCtrl(panel,pos=(70, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreab3=wx.TextCtrl(panel,pos=(130, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreac1=wx.TextCtrl(panel,pos=(10, 110),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreac2=wx.TextCtrl(panel,pos=(70, 110),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreac3=wx.TextCtrl(panel,pos=(130, 110),size=(41,31),style=wx.BORDER_SUNKEN)

        self.PrintAreax1=wx.TextCtrl(panel,pos=(210, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreax2=wx.TextCtrl(panel,pos=(270, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreax3=wx.TextCtrl(panel,pos=(330, 30),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreay1=wx.TextCtrl(panel,pos=(210, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreay2=wx.TextCtrl(panel,pos=(270, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreay3=wx.TextCtrl(panel,pos=(330, 70),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreaz1=wx.TextCtrl(panel,pos=(210, 110),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreaz2=wx.TextCtrl(panel,pos=(270, 110),size=(41,31),style=wx.BORDER_SUNKEN)
        self.PrintAreaz3=wx.TextCtrl(panel,pos=(330, 110),size=(41,31),style=wx.BORDER_SUNKEN)



    def show(self,event):
        a1=self.PrintAreaa1.GetValue()
        a2=self.PrintAreaa2.GetValue()
        a3=self.PrintAreaa3.GetValue()
        b1=self.PrintAreab1.GetValue()
        b2=self.PrintAreab2.GetValue()
        b3=self.PrintAreab3.GetValue()
        c1=self.PrintAreac1.GetValue()
        c2=self.PrintAreac2.GetValue()
        c3=self.PrintAreac3.GetValue()

        a1 = float(a1)
        a2 = float(a1)
        a3 = float(a1)
        b1 = float(a1)
        b2 = float(a1)
        b3 = float(a1)
        c1 = float(a1)
        c2 = float(a1)
        c3 = float(a1)

        x1=self.PrintAreax1.GetValue()
        x2=self.PrintAreax2.GetValue()
        x3=self.PrintAreax3.GetValue()
        y1=self.PrintAreay1.GetValue()
        y2=self.PrintAreay2.GetValue()
        y3=self.PrintAreay3.GetValue()
        z1=self.PrintAreaz1.GetValue()
        z2=self.PrintAreaz2.GetValue()
        z3=self.PrintAreaz3.GetValue()

        x1 = float(x1)
        x2 = float(x2)
        x3 = float(x3)
        y1 = float(y1)
        y2 = float(y2)
        y3 = float(y3)
        z1 = float(z1)
        z2 = float(z2)
        z3 = float(z3)

        a=[[a1,a2,a3],[b1,b2,b3],[c1,c2,c3]]
        b=[[x1,x2,x3],[y1,y2,y3],[z1,z2,z3]]

        print a
        print b
        z=[]
        for p in range(len(a)):
            y=[]
            for i in range(len(a[p])):
                k=0
                for j in range(len(b)):
                    k=k+(a[p][j]*b[j][i])
                y.append(k)
            z.append(y)
        print z


    def closebutton(self,event):
        self.Close(True)

    def closewindow(self,event):
        self.Destroy()
    def macierz(self,event):
        dial=wx.MessageDialog(None,'Lolek','Na co sie patrzysz',wx.OK | wx.ICON_INFORMATION)


        def arr(n):
            array=[]
            for i in range (0,n):
                array.append(0)
            return array
        tablica=arr(5)
        self.printArea.SetValue(str(tablica))

    def panel(self, event):
        AboutFrame().Show()

if __name__ == '__main__':
    app = App(False)
    app.MainLoop()




0
        a1=self.PrintAreaa1.GetValue()
        a2=self.PrintAreaa2.GetValue()
        a3=self.PrintAreaa3.GetValue()
        b1=self.PrintAreab1.GetValue()
        b2=self.PrintAreab2.GetValue()
        b3=self.PrintAreab3.GetValue()
        c1=self.PrintAreac1.GetValue()
        c2=self.PrintAreac2.GetValue()
        c3=self.PrintAreac3.GetValue()
 
        a1 = float(a1) #ładny copypaste, szkoda że z błedem...
        a2 = float(a1)
        a3 = float(a1)
        b1 = float(a1)
        b2 = float(a1)
        b3 = float(a1)
        c1 = float(a1)
        c2 = float(a1)
        c3 = float(a1)
 
        x1=self.PrintAreax1.GetValue()
        x2=self.PrintAreax2.GetValue()
        x3=self.PrintAreax3.GetValue()
        y1=self.PrintAreay1.GetValue()
        y2=self.PrintAreay2.GetValue()
        y3=self.PrintAreay3.GetValue()
        z1=self.PrintAreaz1.GetValue()
        z2=self.PrintAreaz2.GetValue()
        z3=self.PrintAreaz3.GetValue()
 
        x1 = float(x1)
        x2 = float(x2)
        x3 = float(x3)
        y1 = float(y1)
        y2 = float(y2)
        y3 = float(y3)
        z1 = float(z1)
        z2 = float(z2)
        z3 = float(z3)

W pythonie pisać takie okropne kody? Aż mi słabo. Strach pomyśleć jakbyś tam miał mieć na przykład 1000 na 1000. Chciałbym to zobaczyć. Dobry trop to przycisk delete na klawiaturze.

0

programistą to ja cienkim jestem :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1