list(map(lambda p: compute_log_p(X, *p), zip(means, sigmas)))
is technically without a loop, but it's questionable whether it's what is wanted in the exercise
I guess that a good way would be to rewrite compute_log_p and make it directly work for means and sigmas (i.e arrays with dimensions (2,k) and (2,2,k)) by using np.newaxis inside your function.
Exercise subtask (Task C)
Did somebody manage to rewrite the expression below without a loop?
...
for m,s in zip(means,sigmas)
...list(map(lambda p: compute_log_p(X, *p), zip(means, sigmas)))
is technically without a loop, but it's questionable whether it's what is wanted in the exercise
1
NumPy's einsum might help.
I guess that a good way would be to rewrite compute_log_p and make it directly work for means and sigmas (i.e arrays with dimensions (2,k) and (2,2,k)) by using np.newaxis inside your function.
Add comment