Wolfram mathematica 列表输出

Wolfram mathematica 列表输出,wolfram-mathematica,Wolfram Mathematica,Mathematica在我请求嵌套列表的特定元素时给了我一个奇怪的输出 我有: testroots = {{0, 0, 0}, {0, 0, 0}} 当我要求 testroots[[0,0]] 这应该给我一个0,而不是Mathematica说的 我不明白这是为什么或者我做错了什么 谢谢 Mathematica指数从1开始,而不是从零开始。因此testroot的[[0,0]]项不存在。您可以使用 testroots[[1, 1]] 正如b.Gatesucks和bill s所写,Mathema

Mathematica在我请求嵌套列表的特定元素时给了我一个奇怪的输出

我有:

testroots = {{0, 0, 0}, {0, 0, 0}}
当我要求

testroots[[0,0]]
这应该给我一个0,而不是Mathematica说的

我不明白这是为什么或者我做错了什么


谢谢

Mathematica指数从1开始,而不是从零开始。因此testroot的[[0,0]]项不存在。您可以使用

testroots[[1, 1]]

正如b.Gatesucks和bill s所写,Mathematica列表从索引1开始。但是,也允许使用索引0,并给出表达式的
头。那是什么意思

在Mathematica中,列表
{a,b,c}
在内部是一种形式为
list[a,b,c]
的表达式。通过对其应用
FullForm
,您可以看到:

FullForm[{a, b, c}]
(*
==> List[a, b, c]
*)
开口括号前面的部分,此处为
列表
,称为表达式的开头。而
testroot[[0]]
相当于
Head[testroot]
,它为列表提供了
List
。这很有意义,因为在完整表达式中,
列表位于元素之前

但是,您的表达式如何
testroot[[0,0]]
?它访问列表的头。列表的标题是
list
。但是
列表的标题是什么?毕竟,它没有形式
头[arg1,arg2,…]

对于原子表达式,Mathematica给出了描述原子类型的符号。例如
Head[1]
Integer
Head[“Hello”]
String
Head[foo]
Symbol
(假设
foo
未被分配)。请注意,上述形式的表达式的头也可以被视为表达式的类型。列表的类型是
list
,而
a+b
、完整形式的
Plus[a,b]
的类型是
Plus
,即总和

现在
List
是一个符号,因此
Head[List]
symbol
。因此,对于任何列表,如
testroot
testroot[[0,0]]
将计算为
Symbol


要获取列表第一个元素的第一个元素,请使用
testroot[[1,1]]

列表元素从1开始计数,而不是从零开始计数。尝试
testroot[[1,1]]
FullForm[{a, b, c}]
(*
==> List[a, b, c]
*)