[Numpy-discussion] first post, simple questions

Keith Goodman kwgoodman@gmail....
Thu Aug 21 12:55:57 CDT 2008


On Thu, Aug 21, 2008 at 10:40 AM, Prashant Saxena <animator333@yahoo.com> wrote:
> Hi,
>
> numpy rocks!!!
>
> import numpy
> linsp = numpy.linspace
> red = linsp(0, 255, 50)
> green = linsp(125, 150, 50)
> blue = linsp(175, 255, 50)
>
> array's elements are float. How do I convert them into integer?
>
> I need to build a new array from red, green, blue. like this:
>
> [[ red[0], green[0], blue[0] ],
>  [ red[1], green[1], blue[1] ],
>  [ red[2], green[3], blue[3] ],
>  ....
>  ....
>  [ red[49], green[49], blue[49] ],
> ]
>
> how do I create such an array?

Here's one way:

np.c_[red.reshape(-1,1), green.reshape(-1,1), blue.reshape(-1,1)]


More information about the Numpy-discussion mailing list