6

在数学中,

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

2 回答 2

10

版本 6.0 及更高版本包含一个新功能ConstantArray,用于执行此操作,并且比使用更有效Table

In[2]:= ConstantArray[0,10]
Out[2]= {0,0,0,0,0,0,0,0,0,0}

此处的文档:
http ://reference.wolfram.com/mathematica/ref/ConstantArray.html

于 2010-02-28T20:29:38.617 回答
3

在 Mathematica 中,列表和向量之间没有区别。您可以使用该Table函数生成长度为 n 的列表:

x = Table[0, {n}]
(* If n was 4, x would now be the list {0, 0, 0, 0} *)
于 2010-02-27T20:22:04.647 回答