Reputation: 16081
I would like to statically initialize the size of an N by N 2d array in python's numpy where N is a variable (from a SQL query). The equivalent Java would be:
N = code from sql query
int[][] mat = new int[N][N]
How would I do this in numpy? Or what about a Matrix type?
Upvotes: 1
Views: 282
Reputation: 68682
You can do it in a number of ways, but to create an empty array that you will later fill, you might consider:
N = 100
mat = np.empty((N,N))
There are a large number of other methods detailed in the docs:
http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html
Upvotes: 2