Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'float': 0.05; 'subject:How': 0.09; 'subject:create': 0.09; 'subject:python': 0.11; 'assume': 0.11; '100,': 0.16; 'for,': 0.16; 'subject:array': 0.16; 'subject:random': 0.16; 'wrote:': 0.17; 'import': 0.21; 'meant': 0.21; 'work.': 0.23; 'random': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'array': 0.29; 'print': 0.32; 'asked': 0.33; 'to:addr:python-list': 0.33; 'so,': 0.35; 'pm,': 0.35; 'really': 0.36; 'but': 0.36; "didn't": 0.36; 'does': 0.37; 'far': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'received:74.208': 0.71; 'ranging': 0.91; 'responses': 0.93 Date: Tue, 12 Mar 2013 16:52:35 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How can i create a random array of floats from 0 to 5 in python References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Xfts893SL08Jw4OWz3vtOjKmo1nouYJ6VIPxJnettXE Ev2Wonv3KuNFvYDiMh3PM7gx7XcVgYp2FtUDnl5WUSOXn3XchX ChndSsTxlip7X1U8O5eDD4jKNo2LIvASRIbHquZJfXMHbMSXZo ZYSDBq4LLzOE2KnGvgw1Nc6qtsKTS38Tn+SlBGEIxi2ebsLqiC 5fVPlm4X4rhkRPzNIkZhOQMj93OBjYPNp7EVVrQ0pqJSpuoXfU xBuuAFB2+m9RhtKJOvxdyeYK6Fg/rQvITGG3LPdcfBpKyvQYuF aLbEgfYY9vSyxDjBGhfhxk7dqgYW0/8+9V13ixqgwxU04/yJQ= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363121577 news.xs4all.nl 6957 [2001:888:2000:d::a6]:45178 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41150 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