Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matrix convert
#1
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]
Reply
#2
  • 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)]
abbaszandi likes this post
Reply
#3
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)
abbaszandi likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 790 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,305 May-03-2021, 06:30 AM
Last Post: Gribouillis
  matrix from matrix python numpy array shei7141 1 3,643 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020