[Numpy-discussion] how to assign to a "sub set" of an array

Sebastian Haase haase at msg.ucsf.edu
Wed Nov 14 11:08:59 EST 2007


Hi,
First here is some test I ran, where I think the last command shows a bug:

>>> a = N.arange(4); a.shape=2,2; a
[[0 1]
 [2 3]]
>>> aa = N.array((a,a,a)); aa
[[[0 1]
  [2 3]]

 [[0 1]
  [2 3]]

 [[0 1]
  [2 3]]]
>>> N.nonzero(a==0)
([0], [0])
>>> aa[N.nonzero(a==0)] = 5,5; aa
[[[        5 544434034]
  [        2         3]]

 [[        0         1]
  [        2         3]]

 [[        0         1]
  [        2         3]]]


What happend here ?  The value 544434034 is different every time.....
Background:
I have a gray-scale 2D image (in this examples it's a 2x2 pixel image named 'a')
I would like to show this image using grey-values EXCEPT I would like
to show 0-values as blue.
For use with pyOpenGL textures, I convert the image into an RGB image,
in the example called 'aa', with shape 3,2,2.

This is where I'm getting lost, and I tried assigning "something"
(5,5) to aa "only at certain pixels"....
Maybe someone can teach what the proper indexing-constuct, that I
would need to do what I want.

Did I find a bug ?

Thanks,
Sebastian Haase



More information about the NumPy-Discussion mailing list