Initialize numpy array with other numpy arrays

Hello I would like to know whether I can do the following in some other way as this fails with setting an array with a sequence on each of the colour arrays: h,w=720,410 img = ones((h,w,3), uint8)*255 img[ngridn,ngride]=(ncolour[0],ncolour[1],ncolour[2]) pilImage = Image.fromarray(img, 'RGB') where ngridn,ngride,ncolour[m] are all 1-D with the same dimension (effectively ngridn and ngride values map within the bounds of the image) The following works fine: h,w=720,410 img = ones((h,w,3), uint8)*255 img[ngridn,ngride]=(255,0,0) pilImage = Image.fromarray(img, 'RGB') I would prefer not to use indices to solve the problem like the following: (as it is a lot slower) h,w=720,410 img = ones((h,w,3), uint8)*255 for n in range(len(gride)): img[ngridn[n],ngride[n]]=(ncolour[0][n],ncolour[1][n],ncolour[n][2]) pilImage = Image.fromarray(img, 'RGB') It is possible to not use indices and use numpy functions instead. Thanks Frank

On Thu, Feb 19, 2009 at 17:03, Frank Peacock <frank@gis4weather.com> wrote:
Hello
I would like to know whether I can do the following in some other way as this fails with setting an array with a sequence on each of the colour arrays:
h,w=720,410
img = ones((h,w,3), uint8)*255
img[ngridn,ngride]=(ncolour[0],ncolour[1],ncolour[2])
pilImage = Image.fromarray(img, 'RGB')
You probably want to do for i in range(3): img[ngridn,ngride,i] = ncolour[i] -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

On Thu, Feb 19, 2009 at 17:03, Frank Peacock <frank@gis4weather.com> wrote:
img[ngridn,ngride]=(ncolour[0],ncolour[1],ncolour[2])
Le jeudi 19 février 2009 à 18:24 -0600, Robert Kern a écrit :
for i in range(3): img[ngridn,ngride,i] = ncolour[i]
Is it not possible to simply use img[ngridn, ngride, :] = ncolour[:] -- Fabricio

On Fri, Feb 20, 2009 at 02:22, Fabrice Silva <silva@lma.cnrs-mrs.fr> wrote:
On Thu, Feb 19, 2009 at 17:03, Frank Peacock <frank@gis4weather.com> wrote:
img[ngridn,ngride]=(ncolour[0],ncolour[1],ncolour[2])
Le jeudi 19 février 2009 à 18:24 -0600, Robert Kern a écrit :
for i in range(3): img[ngridn,ngride,i] = ncolour[i]
Is it not possible to simply use img[ngridn, ngride, :] = ncolour[:]
No. This would, though: img[ngridn, ngride, :] = ncolour.T -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Fabrice Silva
-
Frank Peacock
-
Robert Kern