tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

How can I use a list to make a matrix? #16

Open nanaa9 opened 6 years ago

nanaa9 commented 6 years ago

How do I create a 3x4 matrix using lists?

matter698no2 commented 6 years ago

You'd have to do the ol' lists in lists thing, where the numbers in the list would represent the columns, and the lists would represent the rows.

if you wanted something like this:

0 0 0 0
0 0 0 0
0 0 0 0

your list would look like:

matrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]

and you could print it out by running it through a for loop, like:

for point in matrix:
     print point

the output of that code should look like this:

[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]