Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82439
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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; 'def': 0.12; 'iterable': 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; 'import': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'sort': 0.25; 'equivalent': 0.26; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'subject:list': 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; 'problem': 0.35; "can't": 0.35; 'computing': 0.35; 'but': 0.35; '(we': 0.36; 'next': 0.36; 'should': 0.36; 'list': 0.37; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'expression': 0.60; 'then,': 0.60; '26,': 0.68; 'subject:over': 0.84; '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 13:32:16 +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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bdb852.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.16905.1418387558.18130.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1418387558 news.xs4all.nl 2958 [2001:888:2000:d::a6]:40109 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:82439 |
Show key headers only | View raw
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".
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