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


Groups > comp.lang.python > #42461

Re: How to do this?

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: How to do this?
Date 2013-04-01 13:28 +0100
References <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4055.1364819291.2939.python-list@python.org> (permalink)

Show all headers | 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