开发者

mathematica -creating lists and vectors of specific length

开发者 https://www.devze.com 2022-12-21 22:37 出处:网络
In Mathematica, How can I cr开发者_运维技巧eate a list of length n and fill with zeroes? How can I

In Mathematica,

  1. How can I cr开发者_运维技巧eate a list of length n and fill with zeroes?
  2. How can I create a vector of length n and fill with zeroes?


Version 6.0 and up include a new function ConstantArray for doing exactly this, and is more efficient than using Table:

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

Documentation here:
http://reference.wolfram.com/mathematica/ref/ConstantArray.html


In Mathematica, there's no distinction between lists and vectors. You can use the Table function to generate a list of length n:

x = Table[0, {n}]
(* If n was 4, x would now be the list {0, 0, 0, 0} *)
0

精彩评论

暂无评论...
验证码 换一张
取 消