0

I was solving the matrix chain problem and I've encountered a dead end.

I have the values of p0,p1,p2,p3,p4,p5 as 4,10,3,12,20,7 respectively

now I want to mark that p0 and p1 combine together to form a matrix of [4][10] size. Similarly p1 and p2 combine to form a matrix of [10][3] size.

please help me in python language

JNevill
  • 46,980
  • 4
  • 38
  • 63

2 Answers2

0
p_list = [p0,p1,p2,p3,p4,p5] = [4,10,3,12,20,7]
m_list = []

for a, b in zip(p_list, p_list[1:]):
    m_list.append([a, b])

m1, m2, m3, m4, m5 = m_list
Vladimir Fokow
  • 3,728
  • 2
  • 5
  • 27
0

you can create a list of the ps then zip together the 0 to n-1 elements with 1 to n and list them:


p = [4,10,3,12,20,7]
m1, m2, m3, m4, m5  =  list( zip( p[:-1],p[1:] ) )
Ulises Bussi
  • 1,635
  • 1
  • 2
  • 14