Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19631 > unrolled thread
| Started by | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| First post | 2012-01-31 07:40 -0500 |
| Last post | 2012-01-31 06:25 -0800 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
surprising result all (generator) (bug??) Neal Becker <ndbecker2@gmail.com> - 2012-01-31 07:40 -0500
Re: surprising result all (generator) (bug??) Mark Dickinson <mdickinson@enthought.com> - 2012-01-31 04:44 -0800
Re: surprising result all (generator) (bug??) Neal Becker <ndbecker2@gmail.com> - 2012-01-31 08:24 -0500
Re: surprising result all (generator) (bug??) Mark Dickinson <mdickinson@enthought.com> - 2012-01-31 06:25 -0800
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Date | 2012-01-31 07:40 -0500 |
| Subject | surprising result all (generator) (bug??) |
| Message-ID | <mailman.5237.1328013618.27778.python-list@python.org> |
I was just bitten by this unexpected behavior: In [24]: all ([i > 0 for i in xrange (10)]) Out[24]: False In [25]: all (i > 0 for i in xrange (10)) Out[25]: True
[toc] | [next] | [standalone]
| From | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| Date | 2012-01-31 04:44 -0800 |
| Message-ID | <3ba87a5d-7092-432e-9bb8-c394fe69fe81@n12g2000yqb.googlegroups.com> |
| In reply to | #19631 |
On Jan 31, 6:40 am, Neal Becker <ndbeck...@gmail.com> wrote: > I was just bitten by this unexpected behavior: > > In [24]: all ([i > 0 for i in xrange (10)]) > Out[24]: False > > In [25]: all (i > 0 for i in xrange (10)) > Out[25]: True What does: >>> import numpy >>> all is numpy.all give you? -- Mark
[toc] | [prev] | [next] | [standalone]
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Date | 2012-01-31 08:24 -0500 |
| Message-ID | <mailman.5239.1328016289.27778.python-list@python.org> |
| In reply to | #19633 |
Mark Dickinson wrote: > On Jan 31, 6:40 am, Neal Becker <ndbeck...@gmail.com> wrote: >> I was just bitten by this unexpected behavior: >> >> In [24]: all ([i > 0 for i in xrange (10)]) >> Out[24]: False >> >> In [25]: all (i > 0 for i in xrange (10)) >> Out[25]: True > > What does: > >>>> import numpy >>>> all is numpy.all > > give you? > > -- > Mark In [31]: all is numpy.all Out[31]: True Excellent detective work, Mark! But it still is unexpected, at least to me.
[toc] | [prev] | [next] | [standalone]
| From | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| Date | 2012-01-31 06:25 -0800 |
| Message-ID | <7897b6ab-3ada-4638-8781-43c7538d483e@i18g2000yqf.googlegroups.com> |
| In reply to | #19635 |
On Jan 31, 7:24 am, Neal Becker <ndbeck...@gmail.com> wrote: > In [31]: all is numpy.all > Out[31]: True > > Excellent detective work, Mark! But it still is unexpected, at least to me. Agreed that it's a bit surprising. It's a consequence of NumPy's general mechanisms for converting arbitrary inputs to arrays: >>> from numpy import asarray >>> asarray([i > 0 for i in range(10)]) array([False, True, True, True, True, True, True, True, True, True], dtype=bool) >>> asarray(i > 0 for i in range(10)) array(<generator object <genexpr> at 0x4688aa8>, dtype=object) So in the second case you get a 0-dimensional array of type 'object', whose only element is that generator object; not surprisingly, the generator object is considered true. As to why it's this way: best to ask on the NumPy mailing lists. It's probably something that's quite difficult to change without breaking lots of code, though. -- Mark
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web