我想创建一个二维坐标矩阵。我希望能够在程序运行时决定行数和列数以及矩阵元素。我知道如何使用我在这里完成的数组来做到这一点:
F = int(raw_input("Enter expected number of frames: "))
P = int(raw_input("Enter expected points to track object: "))
W = []
for i in xrange (2*F):
W.append([])
print "frame number", (i+1)
for j in xrange (P):
W[i].append(int(raw_input("Enter the next coordinate: ")))
print W
我的问题是我如何使用scipy(或numpy)中的矩阵函数来做同样的事情。我想这样做,所以我可以轻松执行反转并计算SVD等。
任何帮助将不胜感激。 谢谢!
答案 0 :(得分:1)
我找到了办法。
以下是我的表现:
import numpy as np
F = int(raw_input("Enter expected number of frames: "))
P = int(raw_input("Enter expected points to track object: "))
W = np.zeros(shape = (2*F, P))
for i in xrange (2*F):
for j in xrange (P):
print "Frame: ", (i+1), "Point: ", (j+1)
W[i][j] = (int(raw_input("Enter the next coordinate: ")))
print W