Registrierung Kalender Mitgliederliste Teammitglieder Suche Häufig gestellte Fragen Zur Startseite

Informatiker Board » Themengebiete » Praktische Informatik » Code funktioniert nicht » Hallo Gast [Anmelden|Registrieren]
Letzter Beitrag | Erster ungelesener Beitrag Druckvorschau | An Freund senden | Thema zu Favoriten hinzufügen
Zum Ende der Seite springen Code funktioniert nicht
Beiträge zu diesem Thema Autor Datum
 Code funktioniert nicht Haevelin 07.06.2016 10:35
 RE: Code funktioniert nicht as_string 14.06.2016 11:23

Autor
Beitrag « Vorheriges Thema | Nächstes Thema »
Haevelin
Tripel-As


Dabei seit: 04.06.2013
Beiträge: 221

Code funktioniert nicht Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

In folgendem Code wandle ich eine smypy Matrix in eine numpy Matrix um, und will dann die Methode np.linalg.det darauf loslassen.


from sympy.matrices import *
from sympy.printing import *
from IPython.display import display, HTML, Math, Latex, clear_output
from ipywidgets import widgets
from random import randint
import numpy as np
from builtins import str

text1 = widgets.Text()

button1 = widgets.Button(description="Auswerten")
button2 = widgets.Button(description="Neue Aufgabe")

#x = np.arange(9).reshape(3,3)
#y = np.arange(3).reshape(3,1)
x=Matrix()
y=Matrix()
latexWidget = widgets.Latex()

taskWidget = widgets.HTML()
taskWidget.value = "<b>Berechnen Sie:</b>"

mhbox1 = widgets.HBox((taskWidget, latexWidget))
mhbox2 = widgets.HBox((button1, button2))

def init_vectors(b):
global x, y, text1
x=zeros(3,3)
y=zeros(3,1)
for i in range(3):
for j in range(3):
x[j,i]=randint(-10,10)

for i in range(1):
for j in range(3):
y[j,i]=randint(-10,10)

#n_matrix_x=np.eye(3)
n_matrix_x=np.matrix(x)

gefunden=False
if np.linalg.det(n_matrix_x)==0:
init_vectors(b)
else:
A,B=np.linalg.eig(n_matrix_x)
for i in range(3):
if A[i].real==0 or A[i].imag!=0:
gefunden=True
break
if gefunden:
init_vectors(b)


text1.value = ""
display_task()

def display_task():
global x, y, latexWidget

clear_output()

a1 = latex(x)
a2 = latex(y)

a1 = a1.replace("left[", "left(")
a2 = a2.replace("left[", "left(")
a1 = a1.replace("right]", "right)")
a2 = a2.replace("right]", "right)")

str1 = "$\langle" + a1 + ", " + a2 + "\\rangle$"
latexWidget.value = str1

def evaluate(b):
global x, y, text1
n_matrix_x=np.array(x)
n_matrix_y=np.array(y)
z = np.linalg.solve(n_matrix_x,n_matrix_y)
w=widgets.Textarea(Description='Lösung GLS',
value=str(z)
)
display(w)

clear_output()
display_task()

if "{0}".format(z) == text1.value:
display(HTML("<b><font color='green'>Richtig</font></b>"))
else:
display(HTML("<b><font color='red'>Falsch</font></b>"))


def exec_la_scalar_1():
init_vectors(button2)
button2.on_click(init_vectors)
button1.on_click(evaluate)
display(widgets.VBox((mhbox1, text1, mhbox2)))




Allerdings erhalte ich für diese Methode die Fehlermeldung: No loop matching the specified signature and casting
was found for ufunc det

Warum funktioniert det nicht?
07.06.2016 10:35 Haevelin ist offline Beiträge von Haevelin suchen Nehmen Sie Haevelin in Ihre Freundesliste auf
as_string as_string ist männlich
Haudegen


Dabei seit: 06.11.2013
Beiträge: 642
Herkunft: Heidelberg

Auf diesen Beitrag antworten Zitatantwort auf diesen Beitrag erstellen Diesen Beitrag editieren/löschen Diesen Beitrag einem Moderator melden       Zum Anfang der Seite springen

Python-Code ohne Einrückung??? Vergiss es.
Mache wenigstens entsprechende CODE-Tags außen rum!

Gruß
Marco

OK, ich habs mal für Dich raus copiert:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
    from sympy.matrices import *
    from sympy.printing import *
    from IPython.display import display, HTML, Math, Latex, clear_output
    from ipywidgets import widgets
    from random import randint
    import numpy as np
    from builtins import str
     
    text1 = widgets.Text()
     
    button1 = widgets.Button(description="Auswerten")
    button2 = widgets.Button(description="Neue Aufgabe")
     
    #x = np.arange(9).reshape(3,3)
    #y = np.arange(3).reshape(3,1)
    x=Matrix()
    y=Matrix()
    latexWidget = widgets.Latex()
     
    taskWidget = widgets.HTML()
    taskWidget.value = "<b>Berechnen Sie:</b>"
     
    mhbox1 = widgets.HBox((taskWidget, latexWidget))
    mhbox2 = widgets.HBox((button1, button2))
     
    def init_vectors(b):
            global x, y, text1
            x=zeros(3,3)
            y=zeros(3,1)
            for i in range(3):
                for j in range(3):
                 x[j,i]=randint(-10,10)
     
            for i in range(1):
                for j in range(3):
                   y[j,i]=randint(-10,10)
           
            #n_matrix_x=np.eye(3)
            n_matrix_x=np.matrix(x)
           
            gefunden=False
            if np.linalg.det(n_matrix_x)==0:
                init_vectors(b)
            else:
                A,B=np.linalg.eig(n_matrix_x)
                for i in range(3):
                   if A[i].real==0 or A[i].imag!=0:
                     gefunden=True
                     break
                if gefunden:
                     init_vectors(b)
               
                     
            text1.value = ""
            display_task()
     
    def display_task():
            global x, y, latexWidget
     
            clear_output()
     
            a1 = latex(x)
            a2 = latex(y)
     
            a1 = a1.replace("left[", "left(")
            a2 = a2.replace("left[", "left(")
            a1 = a1.replace("right]", "right)")
            a2 = a2.replace("right]", "right)")
     
            str1 = "$\langle" + a1 + ", " + a2 + "\\rangle$"
            latexWidget.value = str1
     
    def evaluate(b):
            global x, y, text1
            n_matrix_x=np.array(x)
            n_matrix_y=np.array(y)
            z = np.linalg.solve(n_matrix_x,n_matrix_y)
            w=widgets.Textarea(Description='Lösung GLS',
                     value=str(z)
                     )
            display(w)
     
            clear_output()
            display_task()
     
            if "{0}".format(z) == text1.value:
                    display(HTML("<b><font color='green'>Richtig</font></b>"))
            else:
                    display(HTML("<b><font color='red'>Falsch</font></b>"))
     
     
    def exec_la_scalar_1():
            init_vectors(button2)
            button2.on_click(init_vectors)
            button1.on_click(evaluate)
            display(widgets.VBox((mhbox1, text1, mhbox2)))

Dieser Beitrag wurde 1 mal editiert, zum letzten Mal von as_string: 14.06.2016 11:25.

14.06.2016 11:23 as_string ist offline E-Mail an as_string senden Beiträge von as_string suchen Nehmen Sie as_string in Ihre Freundesliste auf
Baumstruktur | Brettstruktur
Gehe zu:
Informatiker Board » Themengebiete » Praktische Informatik » Code funktioniert nicht