将 turtle pos() 添加到 array/matrix/variable
Add turtle pos() to a array/matrix/variable
我想知道是否可以将 pos()
(乌龟 python)添加到向量或变量中,例如,如果输出 pos()
或 [ 23,12] 并将其保存为 [23,12]
(矩阵 Python)或 n = 23
和 m = 12
.
谢谢
turtle.pos
的文档说
turtle.pos()
Return the turtle’s current location (x,y) (as a Vec2D
vector).
然后转到 turtle.Vec2D
文档
turtle.Vec2D(x,y)
A two-dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs too. Derived from tuple, so a vector is a tuple!
所以它基本上表现得像 tuple
。如果你想把它转换成别的东西,你可以做类似
的事情
a = list(turtle.pos()) # list of values
b = numpy.array(turtle.pos()) # numpy array of values
Vec2D
class具有其他容器所没有的操作,即仿射几何操作,如加、减、内(点)积、向量-标量乘法等
我想知道是否可以将 pos()
(乌龟 python)添加到向量或变量中,例如,如果输出 pos()
或 [ 23,12] 并将其保存为 [23,12]
(矩阵 Python)或 n = 23
和 m = 12
.
谢谢
turtle.pos
的文档说
turtle.pos()
Return the turtle’s current location (x,y) (as aVec2D
vector).
然后转到 turtle.Vec2D
文档
turtle.Vec2D(x,y)
A two-dimensional vector class, used as a helper class for implementing turtle graphics. May be useful for turtle graphics programs too. Derived from tuple, so a vector is a tuple!
所以它基本上表现得像 tuple
。如果你想把它转换成别的东西,你可以做类似
a = list(turtle.pos()) # list of values
b = numpy.array(turtle.pos()) # numpy array of values
Vec2D
class具有其他容器所没有的操作,即仿射几何操作,如加、减、内(点)积、向量-标量乘法等