Python Given r 3 and c 6 create a two dimensional NumPy ar
Python: Given r = 3 and c = 6, create a two dimensional NumPy array A with r rows and c columns. The elements of the array should be i * j, where i is the row index and j is the column index.
How would you do this?
Thanks!
Solution
Python 2.7 code:
import numpy as np
 r = 3;
 c = 6;
 M = np.ndarray(shape = (r,c), dtype = int)
 for i in range(0,r):
    for j in range(0,c):
        M[i][j] = i*j
for i in range(0,r):
    for j in range(0,c):
        print M[i][j],
    print \"\"
Sample Output:
0 0 0 0 0 0
 0 1 2 3 4 5
 0 2 4 6 8 10

