我想在Python中使用矩陣的反函數,並不斷收到語法錯誤。我是Python的新手。在做了一次互聯網搜索並嘗試了多件事之後,我仍然沒有得到它。有人可以看看我的代碼,並指出我在正確的方向嗎? 錯誤消息: python2.6的test.py 文件 「test.py」,第39行 逆= mat1.I * MAT2 ^ 語法錯誤:無效的語法Matrix的反轉Python
謝謝!
#import all of the needed libraries
import math
import matplotlib.pyplot as plt
import numpy
import array
import itertools
from numpy import linalg as LA
#variables and defs
x = []
y = []
h1 = 1
h2 = 5
h3 = 10
x1 = .5
x2 = 9.5
x3 = 4.5
y1 = .5
y2 = 2.5
y3 = 9.5
#create a 10x10 grid
for i in range(10):
for j in range(10):
x.append(i)
y.append(j)
j=0
#Triangle Interpolation Method 3
for i in range(100):
xp = x(i)
yp = y(i)
mat1 = ([[(x1-x3),(x2-x3)],[(y1-y3), (y2-y3)]])
mat2 = ([(xp-x3), (yp-y3)]
inverse = (LA.inv(mat1))*mat2
w1 = inverse(1)
w2 = inverse(2)
w3 = 1-w1-w2
#check to see if the points fall within the triangle
if((w1 <=1 && w1 >=0) && (w2 <=1 && w2 >=0) && (w3 <=1 && w3>=0))
z = (h1*w1)+(h2*w2)+(h3*w3)
.
.
.
在查找有關Exception的幫助時,如'SyntaxError',通常最好至少發佈所涉及的trackback的最後部分,因爲它減少了我們查找錯誤所需的時間。 – Perkins