语法错误:解析时出现意外的EOF - Numpy数组
问题描述:
我正在使用python尝试打印下面的表,其中每个关节的值位于9x1 numpy数组t中。我在解析时继续收到错误SyntaxError:意外的EOF。我试图用各种方法来索引,并继续得到相同的错误。这里是我的打印代码,以及't'和我希望表格的样子。语法错误:解析时出现意外的EOF - Numpy数组
print(" tension compression \nJoint A {0:4.0f} {1:4.0f} \nJoint B {2:4.0f} {3:4.0f} \nJoint C {4:4.0f} {5:4.0f} \nJoint D {6:4.0f} {7:4.0f} \nJoint E {8:4.0f} {9:4.0f}".format(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9])
t = [ 3500. -4041.5704388 2020.7852194 -3464.20323326 2886.83602771
1732.10161663 2598.15242494 -5196.30484988 4500. ]
tension compression
Joint A
Joint B
Joint C
Joint D
Joint E
答
几个问题:
调用
print
当你缺少一个右括号。您使用
t[0]
...t[9]
之前,你甚至可以定义t
。-
t
被定义为“正常”Python列表,但使用无效语法。 Python不能猜测你想t
是一个numpy数组。你需要它来告诉它。import numpy as np t = np.array([3500., -4041.5704388, 2020.7852194, -3464.20323326, 2886.83602771, 1732.10161663, 2598.15242494, -5196.30484988, 4500.])
t
仅包含9个元素,但您尝试访问10 日(t[9]
)。
此外,它似乎是你试图重塑大熊猫数据框。