原文链接:https://www.wolfram.com/language/fast-introduction-for-programmers/en/iterators/
正文
Make a table of the first 10 squares:
制作一个前10个数字平方的表:
![Mathematica入门[6]–Iterators(迭代器)](https://img.mathpretty.com/snipaste_20170925_115110.png)
Many functions in the Wolfram Language use the standard“iterator specification”: min, max, step:
许多在Wolfram中的函数使用标准的迭代规范:最小值,最大值,步长:
An alternative iterator specification just gives an explicit list of values:
一个可以替换的方法是给出列表明确的数组
![Mathematica入门[6]–Iterators(迭代器)](https://img.mathpretty.com/snipaste_20170925_165308.png)
This makes a nested table:
下面这种方法来获得一个嵌套的列表
![Mathematica入门[6]–Iterators(迭代器)](https://img.mathpretty.com/snipaste_20170925_131200.png)
在python中可以使用 ... for i in ... 来达到相同的作用
for i in range(10):
print(i**2)
print("<------------------->")
# 直接将迭代结果保存成数组
a = [i**2 for i in range(10)]
print("语句[i**2 for i in range(10)]的运行结果:",a)
print("语句a[2]:",a[2])
print("语句a+[2]:",a+[2])
print("<------------------->")
# 可以直接往迭代器里输入函数
def single(x):
return(x**2-2)
print([single(i) for i in range(10)])
print("<------------------->")
# 生成高维数组
a=[[i,j] for i in range(3) for j in range(3)]
print(a)
print("<------------------->")
# 先确定i,然后改变j
a = [[i,j] for i in range(3) for j in range(4,6)]
print(a)
![Mathematica入门[6]–Iterators(迭代器)](https://img.mathpretty.com/snipaste_20170925_170724.png)
一些单词和句子
alternative:可供代替的
explicit:明确的
nest:巢
nested:嵌套的
- 微信公众号
- 关注微信公众号
-
- QQ群
- 我们的QQ群号
-


![Mathematica入门[13]–Associations(关联)](https://img.mathpretty.com/20210911_162117_jmo0vhq.jpg)
![Mathematica入门[12]–Options(选项)](https://img.mathpretty.com/20210911_162059_8b2hciq.jpg)
![Mathematica入门[11]–Applying Functions(函数应用)](https://img.mathpretty.com/20210911_162038_sjhj0m3.jpg)
![Mathematica入门[10]–Pure Functions(纯函数)](https://img.mathpretty.com/20210911_162124_pk73t7w.jpg)
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/20210911_162108_oqvo4xz.jpg)
![Mathematica入门[8]–Patterns(模式)](https://img.mathpretty.com/20210911_161424_vlvm1hh.jpg)
![Mathematica入门[4]--Symbolic Expressions(符号表达式)](https://img.mathpretty.com/20210911_162056_tt49p1t.jpg)

评论