Python Forum
Can't modify a simple matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't modify a simple matrix
#1
I'm a beginner in python and I can't understand why this doesn't work like seriously, i really tried. You can see the result of the function on the left, it modify a whole column, i only want to modify one 0 here. Furthermore, the blank matrix (SiteVierge2d) is modified, why ? I made a copy.

My code:

   

SiteVierge2d=[[0]*(8)]*(5) #Le site vierge
def batiment2d(S,b,Origin,T):
    M=S[:]
    x0,y0=Origin
    l,k=T
    for i in range(x0,x0+l):
        for j in range(y0,y0+k):
            M[i][j]=b
    return M
print(batiment2d(SiteVierge2d,'t',(1,1),(2,1))) 
My goal is to make a function that modify the matrix in a form of a rectangle of 'b' (instead of 0). The origin point of the rectangle is x0,y0 and the length and wideness is l,k (but here in the image, everything is just 1), here is what i mean :    

Thx for the help and sorry if this has already been answered somewhere because I didn't find it
Reply


Messages In This Thread
Can't modify a simple matrix - by Lewkiy - Feb-01-2023, 11:33 PM
RE: Can't modify a simple matrix - by Larz60+ - Feb-02-2023, 02:39 AM
RE: Can't modify a simple matrix - by deanhystad - Feb-02-2023, 04:19 AM
RE: Can't modify a simple matrix - by Lewkiy - Feb-05-2023, 02:59 PM

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 841 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,389 May-03-2021, 06:30 AM
Last Post: Gribouillis
  Simple Matrix Assignment m_llaa 10 4,665 Aug-05-2019, 09:35 AM
Last Post: m_llaa
  matrix from matrix python numpy array shei7141 1 3,722 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