On Wed, Aug 26, 2009 at 11:49 PM, Mark Wendell<mark.wend...@gmail.com> wrote: > Figured this much out: if I do an np.copy of the original array to a > new array, then I can edit individual 'color' values with impunity. So > I guess the original array from the pil object still shares memory > with that image object somehow, making it unwritable? > > thanks > Mark > > On Wed, Aug 26, 2009 at 7:48 PM, Mark Wendell <mark.wend...@gmail.com> wrote: >> >> Hi all - I'm playing with editing image data converted from PIL objects, and >> running into a situation where numpy tells me that an 'array is not >> writable'. Not sure I understand what that means, or how to get around it. >> Here's a sample interactive session: >> >> >>> import Image >> >>> import numpy as np >> >>> im = Image.open("rgb.0001.jpg") >> >>> a = np.asarray(im) >> >>> a.shape >> (512, 512, 3) >> >>> a.dtype >> dtype('uint8') >> >>> a[0,0,0] >> 254 >> >>> a[0,0,0] = 10 >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> RuntimeError: array is not writeable >> >> >> Any help appreciated. Thanks, >> Mark >> >> PIL 1.1.6 >> numpy 1.2.1 >> Ubuntu 9.04 >>
Hi Mark, I don't really know the specifics of why your array isn't writeable (someone will have a better answer and will correct me if I'm wrong), but you could try to check if it's writeable by doing: >>> a.flags # or a.flags.writeable And check the value of writeable. It might be as simple as setting a.flags.writeable = True, but then again there might be a good reason why it's unwriteable. I don't really know. Skipper _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion