mathematica-创建特定长度的列表和向量

Mar*_*ion 5 wolfram-mathematica

在Mathematica,

  1. 如何创建长度为n的列表并用零填充?
  2. 如何创建长度为n的向量并用零​​填充?

Mic*_*lat 9

版本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


Ada*_*eld 3

在 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)