[Numpy-discussion] Generating a series of integers

Sebastian Haase haase@msg.ucsf....
Tue Feb 5 04:53:05 CST 2008


On Feb 5, 2008 11:33 AM, Francesc Altet <faltet@carabos.com> wrote:
> Hi,
>
> I need to generate a series of uint8 integers similar to:
>
> In [37]: numpy.linspace(10, 20, num=25).astype('uint8')
> Out[37]:
> array([10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 16,
>        16, 17, 17, 17, 18, 18, 19, 19, 20], dtype=uint8)
>
> i.e. create evenly spaced samples in a range, but without using an
> intermediate array to create it (memory footprint is important).
>
> I know that I can create this with a loop, but I'm curious if that can
> be done more compactly in one single sentence.
>
> Thanks,
>
Could a "dtype" argument be added to linspace() -- there are many
similar functions. (I remember for example fromfunction() )

-Sebastian


More information about the Numpy-discussion mailing list