[英]Strange list outputs in Sage
考慮以下兩行代碼:
對於t
字典, t = {1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
,當我嘗試執行以下操作: list(t[1])
將tuple
轉換為list
,它給我輸出[(0,1)]
。 但是當我執行list(1,0,0,0)
,它給了我(應該如此) [1,0,0,0]
。 這是怎么了?
# given a prime p, return all A_n representations of dimension = p^2
def rankrep(p):
bound = p*p
s = SymmetricFunctions(QQ).schur()
Sym_p = s[p]
A = lambda i: WeylCharacterRing("A{0}".format(i))
deg = []
index = []
L = []
for i in xrange(bound):
deg.append([])
fw = A(i+1).fundamental_weights()
temp = A(i+1)
for j in fw.keys():
deg[i].append(temp(fw[j]).degree())
if temp(fw[j]).degree() == bound:
index.append('A'+str(i+1)+'(fw['+str(j)+'])')
L.append(fw[j])
return index, deg, L
def make_vars2(L):
return dict(enumerate(L, start=1))
[index, deg, L] = rankrep(3)
t = make_vars2(L)
print(t[1])
print t
list(t[1])
給我
(1, 0, 0, 0, 0, 0, 0, 0, 0)
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
[(0, 1)]
即使您的t
看起來像是一本包含整數鍵和整數值元組的字典,但事實並非如此:
sage: t
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
sage: map(type, t)
[int, int]
sage: map(type, t.values())
[sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class,
sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class]
sage: parent(t[1])
Ambient space of the Root system of type ['A', 8]
如果要獲取系數向量,可以使用.to_vector()
。 例如,我們有
sage: t[1]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1])
<class 'sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class'>
sage: list(t[1])
[(0, 1)]
但
sage: t[1].to_vector()
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1].to_vector())
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: list(t[1].to_vector())
[1, 0, 0, 0, 0, 0, 0, 0, 0]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.