Reputation: 2830
I need a negative identity matrix of size (62500 x 62500). declaring a normal identity matrix using numpy works like a charm:
eye = np.eye(62500, 62500)
However, doing something like this
negative_eye1 = np.negative(np.eye(62500, 62500))
# or
negative_eye2 = np.eye(62500, 62500) * -1
will result in this error
Unable to allocate array with shape (62500, 62500) and data type float64
The matrix is then used in a scipy.sparse.bmat()
function, resulting in a csr-matrix, where memory won't be such an issue anymore.
How can I calculate this matrix?
Upvotes: 1
Views: 314
Reputation: 9806
You can use scipy.sparse.eye (sparse matrix with ones on diagonal):
from scipy import sparse
negative_eye = -sparse.eye(62500, 62500)
Upvotes: 1