Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #82457
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: list comprehension return a list and sum over in loop |
| Date | 2014-12-12 17:08 +0100 |
| Organization | None |
| References | (3 earlier) <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16918.1418400523.18130.python-list@python.org> (permalink) |
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