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


Groups > comp.lang.python > #42461

Re: How to do this?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'builtin': 0.09; 'lawrence': 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; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'example': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'array': 0.29; "i'm": 0.30; 'url:wiki': 0.31; 'usually': 0.31; 'url:python': 0.33; "can't": 0.35; 'but': 0.35; 'next': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; "you're": 0.61; 'first': 0.61; "you've": 0.63; 'charset:windows-1252': 0.65; 'subject:this': 0.83; 'ana': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: How to do this?
Date Mon, 01 Apr 2013 13:28:51 +0100
References <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-92-18-43-197.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130307 Thunderbird/17.0.4
In-Reply-To <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com>
X-Antivirus avast! (VPS 130401-0, 01/04/2013), Outbound message
X-Antivirus-Status Clean
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.4055.1364819291.2939.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364819291 news.xs4all.nl 6872 [2001:888:2000:d::a6]:38495
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42461

Show key headers only | View raw


On 01/04/2013 11:14, Ana Dionísio wrote:
> So I have this script:
>
> "
> from numpy import array

Are you aware that this overrides the Python builtin array?  It's 
usually but not always better to do this

import numpy as np
vt = np.array(vt, dtype=dict)

>
> vt=[0]*20
> vt = array(vt, dtype=dict)
>
> for t in range(20):
>      if t == 4:
>          vt[t]=1
>
>      else:
>          vt[t]=0

Why the loop, you've already initialise the array to zeroes?

> "
>
> And have this output:
>
> [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
>
> What I need is when t == 4 I need to put 1 in that position and in the next 3, for example the following output:
>
> [0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]
>
> Do you have any suggestions?

Use slicing.
vt[4:8] = 1

>
>
> I'm sorry if I can't explain this in a better way, English is not my first language
>
> Thank you
>

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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