memory error with python

3789
3
08-16-2011 07:31 AM
IbraheemKhan1
New Contributor III
Hi All,

I developed a python script for geoprocessing. It fails at following line:

import numpy
from numpy import *
n1 = zeros((2962,4625,11))

it says MemoryError

Please can someone help to fix it.

Thanks,
Ibe
Tags (2)
0 Kudos
3 Replies
StacyRendall1
Occasional Contributor III
It fails because you are using a lot of memory (RAM). I tested this out on my computer, and:
n1 = zeros((2962,4476,11))

uses up 1,147,692KB - i.e. about one GB... But:
n1 = zeros((2962,4477,11))

fails; with MemoryError.

Your matrix is bigger than that, so it fails...

This actually doesn't have anything to do with ArcGIS... Try googling 'numpy MemoryError'. If that doesn't work, you have two options:

  1. Make your matrix smaller.

  2. Only if you have a 64bit operating system, AND you don't need to use arcpy functions in your script you could try installing 64bit Python and 64bit Numpy. 64bit programs let you use more RAM than normal; BUT I don't know if this will work, or if it will solve your problem. However this will NOT work with arcpy stuff...

0 Kudos
IbraheemKhan1
New Contributor III
Thanks for reply.

Yes, I noticed same. So far i dont have any workaround to this. ArcGIS 10 enables handling large raster dataset but arcpy on the other hand fails to cater such requirement. I do hope that someone from ESRI can shed some light on this issue.
0 Kudos
StacyRendall1
Occasional Contributor III
Did you try Create Normal Raster (Spatial Analyst)?

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outNormalRaster = CreateNormalRaster(2, Extent(0, 0, 150, 150))
outNormalRaster.save("C:/sapyexamples/output/outnormal")


No idea how big that can go...

Numpy is nothing to do with Arcpy; both are simply libraries that you can use (at the same time, if you want) within the Python programming language. Numpy lets you do complex numerical stuff, Arcpy is way to access Arc functionality programatically...
0 Kudos