Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42455
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '[0,': 0.09; '[0]': 0.09; 'nice!': 0.09; 'python:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'python': 0.11; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'something': 0.35; 'subject:?': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:n 10': 0.64; 'subject:this': 0.83; 'ana': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: How to do this? |
| Date | Mon, 01 Apr 2013 13:32:29 +0200 |
| Organization | None |
| References | <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> <mailman.4051.1364813918.2939.python-list@python.org> <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p5084939b.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4053.1364815917.2939.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364815917 news.xs4all.nl 6852 [2001:888:2000:d::a6]:48346 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42455 |
Show key headers only | View raw
Ana Dionísio wrote:
> Nice! Thank you!
>
> And if I need something like this?
>
> [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0]
>
> How can I do this?
With vanilla Python:
>>> vt = [0] * 20
>>> for i, v in enumerate(vt):
... if 4 <= i < 8 or 13 <= i < 16:
... vt[i] = .17
...
>>> vt
[0, 0, 0, 0, 0.17, 0.17, 0.17, 0.17, 0, 0, 0, 0, 0, 0.17, 0.17, 0.17, 0, 0,
0, 0]
With vanilla Python using slices:
>>> vt = [0] * 20
>>> vt[4:8] = [.17]*4
>>> vt[13:16] = [.17]*3
>>> vt
[0, 0, 0, 0, 0.17, 0.17, 0.17, 0.17, 0, 0, 0, 0, 0, 0.17, 0.17, 0.17, 0, 0,
0, 0]
With numpy:
>>> vt = numpy.zeros(20)
>>> vt[4:8] = vt[13:16] = .17
>>> vt
array([ 0. , 0. , 0. , 0. , 0.17, 0.17, 0.17, 0.17, 0. ,
0. , 0. , 0. , 0. , 0.17, 0.17, 0.17, 0. , 0. ,
0. , 0. ])
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to do this? Ana Dionísio <anadionisio257@gmail.com> - 2013-04-01 03:14 -0700
Re: How to do this? Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-04-01 12:58 +0200
Re: How to do this? Ana Dionísio <anadionisio257@gmail.com> - 2013-04-01 04:08 -0700
Re: How to do this? Peter Otten <__peter__@web.de> - 2013-04-01 13:32 +0200
Re: How to do this? Dave Angel <davea@davea.name> - 2013-04-01 07:53 -0400
Re: How to do this? Ana Dionísio <anadionisio257@gmail.com> - 2013-04-01 04:08 -0700
Re: How to do this? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-01 13:28 +0100
csiph-web