Saturday, 15 March 2014

Why does Python crash when I try to sum this numpy array? -


I am working with Python 3.4 at Ubuntu 14.04 (Nampi 1.9.2 and PIL.Engase 1.1.7). What do I do here:

  gt; & Gt; Image from PIL import & gt; & Gt; & Gt; Np & gt; & Gt; & Gt; Img = Image.open ("./tifs / 18015.pdf_001.tif")> gt; & Gt; & Gt; Arr = np.asarray (img) & gt; & Gt; & Gt; Np.shape (arr) (5847, 4133) & gt; & Gt; & Gt; Arr.dtype dtype ('bool') # In the following four cases where I continually increase # number of rows immediately 700 and immediately; Gt; & Gt; & Gt; V = arr [1: 100,1: 100] .sum (axis = 0)> gt; & Gt; & Gt; V = arr [1: 500,1: 100] .sum (axis = 0)> gt; & Gt; & Gt; V = arr [1: 600,1: 100] .sum (axis = 0)> gt; & Gt; & Gt; V = arr [1: 700,1: 100] .sum (axis = 0) # But suddenly this line is called Python Crash & gt; & Gt; & Gt; V = arr [1: 800,1: 100] .sum (axis = 0) Fish: Job 1, "Python 3" signal ended by SIGSEGV (address boundary error)  

I think the dragon suddenly runs out of memory if this is the case - how can I allocate more memory to Python? As I can see from my 32GB memory capacity HOP, even remotely can not be reduced.

You can download TIFF image.


If I am creating an empty Boolean array, then set the pixel clear and then apply the conference - then it works:

 > Gt; & Gt; Arr = np.empty ((h, w), dtype = bool)> gt; & Gt; & Gt; Arr.setflags (type = true)> gt; & Gt; & Gt; For R in Category (H): & gt; & Gt; & Gt; Limit for C (W): & gt; & Gt; & Gt; Arr.itemset ((r, c), img.getpixel ((c, r))) gt; & Gt; & Gt; V = arr.sum (axis = 0) >> gt; & Gt; V.mean () 5726.8618436970719 & gt; & Gt; & Gt; Arr.shape (5847, 4133)  

But this "solution" is not very satisfactory in copying every pixel, possibly a faster way?

I set my segfault from Ubuntu repository using UMWi v1.8.2 / PIL v1.1.7 Can i

  • If I am installing numpy 1.8.2 in the VirtualWave using Pipe (still using PIL v1.7.1 from Ubuntu repo), then I Do not see segfault.

  • If I use NPP v1.8.2 by using the opposite (using PIL v1.1.7 PIP and Ubuntu repo), I still get the default.

It leads me to believe that this is due to an old bug in numpy. I am not able to find a good candidate in the Issues Tracker in Tracker, but I suspect that updating the issue (such as through the current source or via PIP) will probably resolve this issue.

To convert an alternate solution, convert the image mode to "P" (unsigned 8-bit ints) before turning an array, then converting it back to Boolean:

  arr2 = np.asarray (img (q = 0) 

No comments:

Post a Comment