4 ms·
I've played with J a bit. I have yet to see any J code that can't be translated in a pretty straightforward way to idiomatic Python + Numpy. Of course, it's pr
by yummyfajitas 10y ago
I've played with J a bit. I have yet to see any J code that can't be translated in a pretty straightforward way to idiomatic Python + Numpy.
Of course, it's pretty important to note that idiomatic Numpy is very different from idiomatic Python. For example, here's some idiomatic numpy:
gamma = arange(0,1, 1/1024.0)
x = np.outer(r(T-event_times[M+1:N]), gamma)
log_likelihood += M*log(gamma) + sum(log(1-x), axis=0)
return exp(log_likelihood)
Idiomatic python might be:
for i in range(0,1024):
log_likelihood[i] = M*log(gamma[i])
for j in range(M+1,N):
tmp = r(T-event_times[j])*gamma[i]
log_likelihood[i] += log(1-tmp)
likelihood[i] = exp(log_likelihood[i])
return likelihood
- snaky 10y agohttp://prog21.dadgum.com/121.html http://prog21.dadgum.com/121.html
- yummyfajitas 10y agoPython has the idiom he describes as a builtin. with open(filename) as f: ...your func goes here If you want to create your own custom one: @contextlib.contextmanager def with_a_foo(...): foo = ... yield foo ...cleanup the foo... It's less terse (and in my opinion more readable [1]) than J, but same idea. [1] I very rarely find point free programming to be comprehensible. This may be my mental limitation.