Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70679 > unrolled thread
| Started by | mboyd02255@gmail.com |
|---|---|
| First post | 2014-04-28 06:04 -0700 |
| Last post | 2014-05-01 15:26 +0200 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | mboyd02255@gmail.com |
|---|---|
| Date | 2014-04-28 06:04 -0700 |
| Subject | Convert numpy array to single number |
| Message-ID | <088cdf75-f196-404b-ba77-567559f431d8@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-04-28 14:16 +0000 |
| Message-ID | <535e62a8$0$29965$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #70679 |
On Mon, 28 Apr 2014 06:04:02 -0700, mboyd02255 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. Did you have a question, or are you just sharing? -- Steven D'Aprano http://import-that.dreamwidth.org/
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-04-28 15:19 -0400 |
| Message-ID | <mailman.9554.1398712391.18130.python-list@python.org> |
| In reply to | #70679 |
mboyd02255@gmail.com Wrote in message: > 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. > One thousand and ten is an int, not an array. So is 10, but it seems a more likely value you might be trying for. As for using the builtin binary converters, you'd better be a lot more specific, as you cannot even print an int in decimal form without utilizing them. The number is in binary already. Please copy the exact problem and constraints, as well as what you've written so far and what's wrong with it. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Tom P <werotizy@freent.dd> |
|---|---|
| Date | 2014-04-29 17:42 +0200 |
| Message-ID | <bs9vipF2h3pU1@mid.individual.net> |
| In reply to | #70679 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Papp Győző <pappgyozo@gmail.com> |
|---|---|
| Date | 2014-05-01 15:26 +0200 |
| Message-ID | <mailman.9632.1398970272.18130.python-list@python.org> |
| In reply to | #70714 |
[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 >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web