Sage('Python-like' 语言)属性错误 "IntegerListsLex_with_category.element_class" 对象
Sage ('Python-like' language) Attribute error "IntegerListsLex_with_category.element_class" object
给定一个整数 k,我编写了一种方法来对 k 进行所有分区,使得
(1) 每个分区最多有n个条目(这里也给出了n)
(2) 每个分区没有任何重复的奇数。
我还按降序对这些分区列表进行了分类。但是,我无法将零附加到列表中任何给定分区的末尾,以便所有分区都是 n 元组。
# Define n and k
(k, n) = (10, 5)
# Find partitions of k of max length n, and put partitions in list B
B = Partitions(k, max_length=n).list()
# Extracts partitions with repeated odd components and creates a separate list for them, namely B_Repeated_Odds
B_Repeated_Odds = []
for i in range(0, len(B)):
for j in range(0, len(B[i])):
for l in range(0, len(B[i])):
if B[i][j]%2 == 1:
if B[i][l]%2 == 1:
if B[i][j] == B[i][l]:
if j != l:
B_Repeated_Odds.append(B[i])
# Remove duplicates from B_Repeated_Odds
B_Unique = uniq(B_Repeated_Odds)
# Remove unwanted partitions from original list B, and sort finalized list in descending order
Improper_Part = Set(B).difference(Set(B_Unique))
Proper_Part = sorted(Improper_Part, reverse=true)
for i in range(0, len(Proper_Part)):
while len(Proper_Part[i]) < n:
Proper_Part[i].append(0)
上述问题出现在最后三行代码中,错误消息显示 "Attribute Error: 'IntegerListsLex_with_category.element_class' object has no attribute 'append'."
我的具体问题是如何将列表 Proper_Part 中的分区类型从 IntegerListsLex_with_category.element_class 更改为列表(或适用于追加命令的任何其他对象)?或者,如果有人看到更好的方法,我很乐意听到。
为了回答我自己的问题,最下面三行代码的合适替换如下:
# Convert each partition from IntegerListsLex_with_category.element object to list
C = []
for i in range(0, len(Proper_Part)):
C.append(list(Proper_Part[i]))
while len(C[i]) < n:
C[i].append(0)
给定一个整数 k,我编写了一种方法来对 k 进行所有分区,使得
(1) 每个分区最多有n个条目(这里也给出了n)
(2) 每个分区没有任何重复的奇数。
我还按降序对这些分区列表进行了分类。但是,我无法将零附加到列表中任何给定分区的末尾,以便所有分区都是 n 元组。
# Define n and k
(k, n) = (10, 5)
# Find partitions of k of max length n, and put partitions in list B
B = Partitions(k, max_length=n).list()
# Extracts partitions with repeated odd components and creates a separate list for them, namely B_Repeated_Odds
B_Repeated_Odds = []
for i in range(0, len(B)):
for j in range(0, len(B[i])):
for l in range(0, len(B[i])):
if B[i][j]%2 == 1:
if B[i][l]%2 == 1:
if B[i][j] == B[i][l]:
if j != l:
B_Repeated_Odds.append(B[i])
# Remove duplicates from B_Repeated_Odds
B_Unique = uniq(B_Repeated_Odds)
# Remove unwanted partitions from original list B, and sort finalized list in descending order
Improper_Part = Set(B).difference(Set(B_Unique))
Proper_Part = sorted(Improper_Part, reverse=true)
for i in range(0, len(Proper_Part)):
while len(Proper_Part[i]) < n:
Proper_Part[i].append(0)
上述问题出现在最后三行代码中,错误消息显示 "Attribute Error: 'IntegerListsLex_with_category.element_class' object has no attribute 'append'."
我的具体问题是如何将列表 Proper_Part 中的分区类型从 IntegerListsLex_with_category.element_class 更改为列表(或适用于追加命令的任何其他对象)?或者,如果有人看到更好的方法,我很乐意听到。
为了回答我自己的问题,最下面三行代码的合适替换如下:
# Convert each partition from IntegerListsLex_with_category.element object to list
C = []
for i in range(0, len(Proper_Part)):
C.append(list(Proper_Part[i]))
while len(C[i]) < n:
C[i].append(0)