Наборы индексов (SymPy)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Создать матрицу индексов
[symbols('x'+str(i)+':'+str(i+1)+':'+str(m)) for i in xrange(m)]
#[(x00, x01, x02, x03, x04, x05, x06, x07, x08, x09),
# (x10, x11, x12, x13, x14, x15, x16, x17, x18, x19),
# (x20, x21, x22, x23, x24, x25, x26, x27, x28, x29),
# (x30, x31, x32, x33, x34, x35, x36, x37, x38, x39),
# (x40, x41, x42, x43, x44, x45, x46, x47, x48, x49),
# (x50, x51, x52, x53, x54, x55, x56, x57, x58, x59),
# (x60, x61, x62, x63, x64, x65, x66, x67, x68, x69),
# (x70, x71, x72, x73, x74, x75, x76, x77, x78, x79),
# (x80, x81, x82, x83, x84, x85, x86, x87, x88, x89),
# (x90, x91, x92, x93, x94, x95, x96, x97, x98, x99)]
#Создать усечённую матрицу индексов
[symbols('x'+str(i)+':'+str(i+1)+':'+str(i+1)) for i in xrange(m)]
# [(x00,),
# (x10, x11),
# (x20, x21, x22),
# (x30, x31, x32, x33),
# (x40, x41, x42, x43, x44),
# (x50, x51, x52, x53, x54, x55),
# (x60, x61, x62, x63, x64, x65, x66),
# (x70, x71, x72, x73, x74, x75, x76, x77),
# (x80, x81, x82, x83, x84, x85, x86, x87, x88),
# (x90, x91, x92, x93, x94, x95, x96, x97, x98, x99)]
#Создать списки индексов переменной длины
counters = [1, 7, 2, 9, 5]
[symbols('x'+str(i)+':'+str(i+1)+':'+str(counters[i])) for i in xrange(len(counters))]
#[(x00,),
# (x10, x11, x12, x13, x14, x15, x16),
# (x20, x21),
# (x30, x31, x32, x33, x34, x35, x36, x37, x38),
# (x40, x41, x42, x43, x44)]