0

for the purpose of analytical inversion array study, I need to build a diagonal matrix with a shape (250000, 250000).

nx=500
ny=500
D=np.diag(np.full(nx*ny,1.,dtype=np.float32))
Dinv=inv(D)

Unfortunately it seems that this array is too big (??), and I get this error message :

MemoryError: Unable to allocate array with shape (250000, 250000) and data type float32

How can I solve this error ?

frank
  • 89
  • 5
  • 5
    Oh yes it's definitely too big, because 250k * 250k = 62.5 billion elements, times 4 bytes for the 32-bit data type = 250 billion bytes, that means you'd need 250 GB (232.8 GiB) RAM just for holding that array. Think about another way to achieve your goal unless you are going to run it on a huge AWS instance that costs $3k+/month... – CherryDT Apr 17 '21 at 09:45
  • as said above get more ram and a system that can handle it – pippo1980 Apr 17 '21 at 09:54
  • Very large matrices using Python and NumPy: https://stackoverflow.com/questions/1053928/very-large-matrices-using-python-and-numpy – pippo1980 Apr 17 '21 at 09:55

0 Answers0