[Numpy-discussion] Initialize numpy array with other numpy arrays

Frank Peacock frank at gis4weather.com
Thu Feb 19 18:03:58 EST 2009


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090219/5f1aa510/attachment.html>


More information about the NumPy-Discussion mailing list