import numpy

def a(m, n):
    array = numpy.zeros((m, n))

    for i in range(m):
        for j in range(n):
            array[i, j] = i * j

    return array

def main():
    m = 3
    n = 4

    array = a(m, n)

    print(array)

if __name__ == "__main__":
    main()
  1. Import statement

    import numpy
    

    This line imports the numpy library so that we can use numpy arrays and its associated functions.

  2. Function definition:

    def a(m, n):
        array = numpy.zeros((m, n))
    
        for i in range(m):
            for j in range(n):
                array[i, j] = i * j
    
        return array
    
  3. Main function:

    def main():
        m = 3
        n = 4
    
        array = a(m, n)
    
        print(array)
    
  4. Condition to run main():

    if __name__ == "__main__":
        main()
    

    This is a common Python idiom to ensure that main() is executed only if the script is run directly (not imported as a module by another script).


How it works all together

When main() is called:

Thus, the resulting 2D array is:

[[0. 0. 0. 0.]
 [0. 1. 2. 3.]
 [0. 2. 4. 6.]]