numpy column_stack - why does this work?

PythonDude mjoerg.phone at gmail.com
Mon Nov 16 03:02:09 EST 2015


On Friday, 13 November 2015 18:17:59 UTC+1, Ian  wrote:
> On Fri, Nov 13, 2015 at 8:37 AM, PythonDude <mjoexxxxx.com> wrote:
> > 3) I DON'T understand why the code doesn't look like this:
> >
> > means, stds = np.column_stack([
> >     for _ in xrange(n_portfolios):
> >       getMuSigma_from_PF(return_vec) ])
> 
> Because that would be invalid syntax; you can't put a for loop inside
> an expression like that. Your question is not about numpy.column_stack
> at all, but about list comprehensions. I suggest you start by reading
> this:
> 
> https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions
> 
> Then if you're still confused, come back and ask further questions.

Thank you very much, I'll look careful into that before asking again :-)



More information about the Python-list mailing list