|
From: Benjamin R. <ben...@ou...> - 2011-01-14 20:03:43
|
On Fri, Jan 14, 2011 at 1:40 PM, sprobst <Ste...@gm...> wrote:
>
> Hi all,
>
> I tried to plot parts of a large 3D array with each 4 float64 entries.
> Loading the array with numpy.fromfile and performing a type conversion
> afterwards ends up in a MemoryError.
>
> The following code reproduces the error:
> ***********************************
> import gc
>
> from os import path
> from numpy import zeros, empty, float32, float64, fromfile
>
> # With the imports of the next three lines a memory error occurs
> #import matplotlib
> #matplotlib.use("AGG")
> #import matplotlib.pylab as plt
>
> _filename = "mt.dat"
>
> if (path.exists(_filename)==False):
> print "Write file ..."
> _mtf = file(_filename, "wb")
> _mtd = zeros( (300,300,300,4),dtype=float64)
> _mtd.tofile(_mtf)
> _mtf.close()
>
> _mtd = empty((0))
> gc.collect();
>
> print "Try to read file ..."
>
> _mtf = file(_filename, "rb")
> # The memory error occurs with the type conversion to float 64,
> # but only if mathplotlib is imported!
> _mtd = fromfile(_mtf,float64).astype(float32)
> _mtf.close()
>
> print "Successful read:",_mtd.shape
>
> # Here some plot stuff would be :)
> ***********************************
>
> If the import of matplotlib is not included, no error occures otherwise it
> will not work. Perhaps anybody can help me (I tested it only on a Windows
> XP
> 32Bit).
>
> Best regards and thank you
> Stefan
>
Stefan,
I don't know if it would make a difference, but I see that you are importing
matplotlib.pylab as plt. This is not a typical way of importing
matplotlib. Try instead:
import matplotlib.pyplot as plt
Ben Root
|