Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41150 > unrolled thread

Re: How can i create a random array of floats from 0 to 5 in python

Started byDave Angel <davea@davea.name>
First post2013-03-12 16:52 -0400
Last post2013-03-12 16:52 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How can i create a random array of floats from 0 to 5 in python Dave Angel <davea@davea.name> - 2013-03-12 16:52 -0400

#41150 — Re: How can i create a random array of floats from 0 to 5 in python

FromDave Angel <davea@davea.name>
Date2013-03-12 16:52 -0400
SubjectRe: How can i create a random array of floats from 0 to 5 in python
Message-ID<mailman.3251.1363121577.2939.python-list@python.org>
On 03/12/2013 01:11 PM, Norah Jones wrote:
> I want to create a random float array of size 100, with the values in the array ranging from 0 to 5. I have tried random.sample(range(5),100) but that does not work. How can i get what i want to achieve?
>
>

None of the responses so far actually give you what you asked for, as 
they assume you didn't mean 'array' but meant 'list.'  I suspect they're 
right, but here's an approach for array.array.

If you really want a multiprocess.Array, or numpy's array, please say 
so, and somebody'll tell you how to put random numbers in one of them.



import array
import random

floats = (random.random() * 5 for _ in xrange(100))
data = array.array('d', floats)

print data
print type(data)



-- 
DaveA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web