Mar*_*ion 5 wolfram-mathematica
在Mathematica,
版本6.0及更高版本包含一个新功能ConstantArray,可以完成此操作,并且比使用更高效Table:
In[2]:= ConstantArray[0,10]
Out[2]= {0,0,0,0,0,0,0,0,0,0}
Run Code Online (Sandbox Code Playgroud)
文档:http:
//reference.wolfram.com/mathematica/ref/ConstantArray.html
在 Mathematica 中,列表和向量之间没有区别。您可以使用该Table函数生成长度为 n 的列表:
x = Table[0, {n}]
(* If n was 4, x would now be the list {0, 0, 0, 0} *)
Run Code Online (Sandbox Code Playgroud)