Building An Nxn Matrix In Python Numpy, For Any N
Is it possible using numpy for python (versions 3.3) to write the code for building an nxn matrix, without specifying n? I need to index the entries as A_i,j or something like that
Solution 1:
You can create an empty n
xn
array:
import itertools
import numpy as npmy_array= np.empty([n, n])
Then set the value at coordinate i, j
to f(i, j)
.
for i, j in itertools.product(range(n), range(n)):
my_array[i, j] = f(i, j)
Post a Comment for "Building An Nxn Matrix In Python Numpy, For Any N"