Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70819
| References | <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> <bs9vipF2h3pU1@mid.individual.net> |
|---|---|
| From | Papp Győző <pappgyozo@gmail.com> |
| Date | 2014-05-01 15:26 +0200 |
| Subject | Re: Convert numpy array to single number |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9632.1398970272.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Maybe something like this? >>> to_num = lambda array: np.sum(array * 2**np.arange(len(array)-1, -1, -1)) >>> to_num(np.array([1,0,1,0])) 10 2014-04-29 17:42 GMT+02:00 Tom P <werotizy@freent.dd>: > On 28.04.2014 15:04, mboyd02255@gmail.com wrote: > >> I have a numpy array consisting of 1s and zeros for representing binary >> numbers: >> >> e.g. >> >> >>> binary >> array([ 1., 0., 1., 0.]) >> >> I wish the array to be in the form 1010, so it can be manipulated. >> >> I do not want to use built in binary converters as I am trying to build >> my own. >> >> > Do you mean that each element in the array represents a power of two? > So array([ 1., 0., 1., 0.]) represents 2^3 + 2 = 6 decimal? > > -- > https://mail.python.org/mailman/listinfo/python-list >
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Convert numpy array to single number mboyd02255@gmail.com - 2014-04-28 06:04 -0700
Re: Convert numpy array to single number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-28 14:16 +0000
Re:Convert numpy array to single number Dave Angel <davea@davea.name> - 2014-04-28 15:19 -0400
Re: Convert numpy array to single number Tom P <werotizy@freent.dd> - 2014-04-29 17:42 +0200
Re: Convert numpy array to single number Papp Győző <pappgyozo@gmail.com> - 2014-05-01 15:26 +0200
csiph-web