[Tutor] Numpy unexpected result: subtraction of cell values
marc.tompkins at gmail.com
Mon Jan 11 19:47:38 CET 2010
On Mon, Jan 11, 2010 at 10:20 AM, Carnell, James E <
jecarnell at saintfrancis.com> wrote:
> I'm sure this is easy, but I am having a difficult time finding the right
> search terms to find it on the Internet. Any help much appreciated.
> 3 dimensional array(x,y,rgb) which is a PIL image into a numpy array using
> 'asarray' function.
> I want to subtract the Red Value in an array cell from a neighboring Red
> Value cell.
> >>> pictArray #pixel at 39 4
> array([150, 140, 120], dtype=unint8)
> >>> pictArray #pixel at 39 5
> array([160, 150, 120], dtype=unint8)
> >>> pictArray #red pixel
> >>> pictArray[5 #neighboring red pixel
> >>> pictArray - pictArray )
> 246 # <--------------- ??? vs -10
> How do I get the number -10? Does this have to do with the dtype?
It looks like you're re-typing from your terminal window into your Compose
window... your life (and ours!) will be simpler if you just cut and paste.
There are a couple of weirdnesses in what you posted - unmatched parentheses
and such - that are probably just typos.
Anyway, assuming that what you've posted IS the same as what you're trying
to do, in your last line you're trying to subtract one entire cell from
another (instead of just the red value of one from the red value of the
other.) I don't know where the number 246 came from, but I'm not really
sure what number I would have expected anyway (matrix algebra was a LONG
time ago, I'm afraid!)
I think what you want to do is
>>> pictArray - pictArray
I'm not in a place where I can test, but I think that should do it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor