1

我想创建一个二维坐标矩阵。我希望用户能够在程序运行时决定行数和列数,以及矩阵的元素。我知道如何使用我在这里完成的数组来做到这一点:

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 等。

任何帮助将不胜感激。谢谢!

4

1 回答 1

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
于 2013-02-16T16:05:16.100 回答