Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82457
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.04; 'base.': 0.05; 'element': 0.07; 'list?': 0.07; 'problem:': 0.07; 'skip:" 60': 0.07; '34,': 0.09; '[0,': 0.09; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:c 10': 0.09; 'python': 0.11; 'def': 0.12; '"from': 0.16; 'imports': 0.16; 'iterable': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'typeerror:': 0.16; 'weird': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'issue.': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'environment': 0.24; 'sort': 0.25; 'equivalent': 0.26; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'installed': 0.27; 'idea': 0.28; 'subject:list': 0.30; "i'm": 0.30; 'code': 0.31; 'away.': 0.31; 'probability': 0.31; 'writes:': 0.31; 'file': 0.32; 'probably': 0.32; 'run': 0.32; '(most': 0.33; 'bugs': 0.33; 'sense': 0.34; 'maybe': 0.34; 'problem': 0.35; "can't": 0.35; 'computing': 0.35; 'but': 0.35; 'version': 0.36; '(we': 0.36; 'next': 0.36; "didn't": 0.36; 'should': 0.36; 'list': 0.37; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'that,': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'even': 0.60; 'expression': 0.60; 'then,': 0.60; 'skip:n 10': 0.64; '26,': 0.68; 'subject:over': 0.84; '8bit%:70': 0.91; 'that),': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: list comprehension return a list and sum over in loop |
| Date | Fri, 12 Dec 2014 17:08:28 +0100 |
| Organization | None |
| References | <fa1c4908-8fde-424a-87af-f9741b682c37@googlegroups.com> <mailman.16893.1418368651.18130.python-list@python.org> <d03ea4ee-a361-4901-b799-d7d1c5f85ee5@googlegroups.com> <mailman.16901.1418375626.18130.python-list@python.org> <a5c1fd3e-1724-4ade-9c64-27ab0ec8be37@googlegroups.com> <qota92ti0ks.fsf@ruuvi.it.helsinki.fi> <mailman.16905.1418387558.18130.python-list@python.org> <1531593e-8dac-4b85-b838-3783717249c2@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Gmane-NNTP-Posting-Host | p57bd892c.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16918.1418400523.18130.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418400523 news.xs4all.nl 2866 [2001:888:2000:d::a6]:42117 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82457 |
Show key headers only | View raw
KK Sasa wrote: > Peter Otten於 2014年12月12日星期五UTC+8下午8時32分55秒寫道: >> Jussi Piitulainen wrote: >> >> > KK Sasa writes: >> > >> >> def p(x,t,point,z,obs): >> >> d = x[0] >> >> tau = [0]+[x[1:point]] >> >> a = x[point:len(x)] >> >> at = sum(i*j for i, j in zip(a, t)) >> >> nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] >> >> de = sum(nu, axis=0) >> >> probability = [nu[k]/de for k in xrange(point)] >> >> return probability[obs] >> > >> > I must be blind, but this looks like computing a whole probability >> > distribution and then throwing almost all of it away. >> > >> > Can't this just return nu[obs]/de? >> > >> > The expression for tau also seems weird to me. Isn't it equivalent to >> > [0, x[1:point]], a two-element list with the second element a list? >> > How can sum(tau[k]) work at all then, for any k > 1? >> >> Also, after adding >> >> from numpy.random import seed >> >> to the code I run into the next problem: >> >> Traceback (most recent call last): >> File "hessian.py", line 34, in <module> >> re = [d2(x,t[k],2,z,1) for k in range_people] >> File "/home/petto/.local/lib/python2.7/site-packages/ad/__init__.py", >> line >> 1114, in hess >> return func(xa, *args).hessian([xa]) >> File "hessian.py", line 26, in p >> nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] >> TypeError: 'int' object is not iterable >> >> OP: Optimizations only make sense when you can start from a known-good >> base. You should sort out the logic of your problem (we probably can't >> help you with that), then fix the bugs in your code and only then revisit >> the "speed issue". > > I have no idea why you added "from numpy.random import seed" to this > syntax. Even I added that, my python didn't complain any bugs inside. > Maybe your ad package was not be installed correctly? It may be a version issue. I'm using >>> import ad, numpy >>> ad.__version__ '1.2.2' >>> numpy.__version__ '1.9.1' Or are you using an environment that does some imports automatically?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-11 22:22 -0800
Re: list comprehension return a list and sum over in loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-12 07:17 +0000
Re: list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-12 00:30 -0800
Re: list comprehension return a list and sum over in loop Christian Gollwitzer <auriocus@gmx.de> - 2014-12-12 10:09 +0100
Re: list comprehension return a list and sum over in loop Peter Otten <__peter__@web.de> - 2014-12-12 10:13 +0100
Re: list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-12 01:45 -0800
Re: list comprehension return a list and sum over in loop Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-12 13:12 +0200
Re: list comprehension return a list and sum over in loop Peter Otten <__peter__@web.de> - 2014-12-12 13:32 +0100
Re: list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-12 05:09 -0800
Re: list comprehension return a list and sum over in loop Peter Otten <__peter__@web.de> - 2014-12-12 17:08 +0100
Re: list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-12 19:04 -0800
Re: list comprehension return a list and sum over in loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-12-13 11:27 +0000
Re: list comprehension return a list and sum over in loop KK Sasa <genwei007@gmail.com> - 2014-12-12 05:03 -0800
Re: list comprehension return a list and sum over in loop Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-12 20:46 +1100
Re: list comprehension return a list and sum over in loop Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-12-12 16:47 +0000
Re: list comprehension return a list and sum over in loop pecore@pascolo.net - 2014-12-13 13:38 +0100
csiph-web