[英]sympy: Vector/Matrix repetition
What is the most elegant way in sympy
to construct a matrix from a repeated vector. sympy
从重复向量构造矩阵的最优雅方法是什么。 That is, given a row vector 也就是说,给定行向量
V = [ v00, v01, v02 ]
the goal is to find an operation op
such that 目标是找到一个操作
op
M = op(V, N)
delivers a matrix M
consisting of N
rows which are equal to V
, ie 传递由等于
V
的N
行组成的矩阵M
,即
/ v00 v01 v02 \
| v00 v01 v02 |
M = | ... |
| |
\ v00 v01 v02 /
similar to what can be achieved by tile
in numpy
. 类似于
numpy
的tile
可以实现的功能。
I cannot gurantee that this is the most elegant way to do it and probably you are already using something like this but the following works: 我不能保证这是最优雅的方法,可能您已经在使用类似的方法了,但以下工作原理:
import sympy as s
def copyRow(N,V):
M = V
for i in range(N):
M = M.row_insert(1,V)
return M
v00,v01,v02 = s.symbols('v00,v01,v02')
V = s.Matrix([ [v00, v01, v02 ] ])
M = copyRow(5,V)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.