How to create a matrix? (Python)
Question: I want to create a 2x3 matrix. (2 rows, 3 columns) When I run my code, I get
the matrix in parentheses, which is incorrect.

    
    
    def fill_matrix(numrows, numcols, val):
         matrix = [[val for i in range(numrows)] for j in range(numcols)]
         return (numrows, numcols, val)
    

If I choose to create a 2x2 matrix and fill all holes with 1, I'm supposed to
get this: [[1, 1], [1, 1]]

But I get this instead: (2, 2, 1)


Answer: Your `fill_matrix` function returns the tuple `(numrows, numcols, val)`, which
is why you're getting `(2,2,1)`. You're not returning the matrix at all.

You could try:

    
    
    def fill_matrix(numrows, numcols, val):
         return [[val for i in range(numrows)] for j in range(numcols)]
    

to just return the matrix itself.

If you're working with matricies you might also consider using
[numpy](http://www.numpy.org/) and doing:

    
    
    import numpy as np
    np.ones((2,2))
    

or:

    
    
    def fill_matrix(numrows, numcols, val):
        return np.ones((numrows, numcols)) * val
    

