【问题标题】:Strange list outputs in SageSage 中的奇怪列表输出
【发布时间】:2013-05-31 15:07:05
【问题描述】:

考虑以下两行代码:

对于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)]

【问题讨论】:

  • @DSM 我已经添加了我的成绩单,它对你有用确实很奇怪。而且我不确定我是否理解您的第二条评论,即,我不确定您的“print list is _builtin_.list”应该输入什么
  • 感谢您的更新——它清楚地说明了发生了什么。您的代码与建议的原始示例大不相同,因为t[1] 不是tuple,而是AmbientSpace_with_category.element_class

标签: python list sage


【解决方案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]

【讨论】:

  • 啊哈!非常感谢@DSM
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多