Python Forum

Full Version: matrix convert
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to convert a to b

a=[1,2,3,4,5,...,377]
b=[Image: photo_%DB%B2%DB%B0%DB%B2%DB%B0_%DB%B1%DB...%DB%B9.jpg]
  • set numrows = 7
  • set rowindex = numrows - 1
  • Create an empty 2D list with numrows sublists
  • within a loop with range of 1 - 378:
    • append loop index to sublist [rowindex]
    • subtract 1 from rowindex - set to 0 if -1

Hint: you can create empty 2D list with: mylist = [[] for _ in range(numrows)]
def reshape(src, rows):
    columns = len(src) // rows
    return [src[c*rows-r] for r in range(1,rows+1) for c in range(1,columns+1)]

x = list(range(1, 378))
y = reshape(x, 13)