1

The matrix represents cell points. If we imagine these cell points being a grid, we need to make the values within the matrix equal to the input T1 in quadrants 2 and 4 and the values input T2 for quadrants 1 and 3. As in, from row 0 to 2 and column 0 to 3 it should be the value T1. Also, I need to make this appear as cells, with lines in between all rows/columns.

#input values needed
A = input("Enter a value for the first heater/cooler temp: ")
B = input("Enter a value for the second heater/cooler temp: ")
T1 = input("Enter a value for the first initial plate temp: ")
T2 = input("Enter a value for the second initial plate temp: ")
#the stabilizing criterion value


matrix = []
for row in range(0,6):
    matrix.append([])
    for column in range(0,9):
        matrix[row].append(column)

for row in matrix:
    print(row)
5
  • I'm not sure what your question is asking. You can set a value in a nested list like this: matrix[row][column] = T1 for the particular range of rows and columns that you need. Commented Nov 18, 2015 at 1:11
  • how do I do it with a range? if I say matrix[0][0] = 3 then I know that the first item of the first row will be 3. I just don't know how to do this over a loop Commented Nov 18, 2015 at 1:13
  • Right now, you are looping over various values of row and column. You can check if a particular value of row and column falls within the desired range, and if so, set matrix[row][column] to T1 or T2, whichever. Does that make sense? Commented Nov 18, 2015 at 1:15
  • so would it be: if row in matrix[0][3]: if column in matrix[0][4]: matrix.append(T1)? is that what you mean? My problem is I just don't grasp indexing all that well Commented Nov 18, 2015 at 1:20
  • So, matrix[0][3] refers to the value stored in a particular position of the matrix. Since you have initialized it to take values of row and column, row in matrix[0][3] checks if the value of row is in the value stored at matrix[0][3]. If you need to check certain positions, you can check if row falls in the range 0 to 3: if row in range(3) and then set it to your desired value accordingly. Commented Nov 18, 2015 at 1:22

1 Answer 1

1

In this code, row in range(0,6) refers to all positions of the matrix that are in the first row, then second, and so on. It loops over all the rows. So matrix[0][x] refers to all the positions in the 0th row (and you can access each position by setting x = 1, 2, ...).

What you want to do, is set values to T1 for a specific set of rows and columns, right?

Since you are anyway looping through all the rows and columns, you can check if at any point, the combination of row and column falls in the desired range:

if row < 3 and column < 4:
    matrix[row][column] = T1

What this does is, whenever the combination of row and column numbers falls in the range that is, row = 0 to 2 and column = 0 to 3, it sets the value at those positions in the matrix, to T1.

Does this answer your question?

Now about the printing part, you can try a function like this:

def printy(P):
    for i in range(len(P[0])):
        print '---',
    print

    for i in range(len(P)):
        for j in range(len(P[0])):
            print P[i][j], '|',
        print
        for i in range(len(P[0])):
            print '---',
        print
Sign up to request clarification or add additional context in comments.

7 Comments

What you're saying makes sense to me but I plugged it in and nothing is changing to the matrix. Does it need to be within the for loop?
Yes, it needs to be within the for-loop. Alternatively, after you initialized it the way you have in your code, you can run another for loop to go over all values of row and column and then include this condition.
alright thanks! I got it to work. Now I just need to make it into rows and columns, but that is another task
Yes, I didn't understand that part of your question. Do you mean in the way that it prints?
yeah, I can get lines in between rows you know like print("-"*20) but I don't know how to make vertical lines in between the columns, but really you don't have to stick around all day helping me understand this if you don't want
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.