[Numpy-discussion] array comprehension
faltet at gmail.com
Fri Nov 4 08:26:10 EDT 2016
2016-11-04 13:06 GMT+01:00 Neal Becker <ndbecker2 at gmail.com>:
> I find I often write:
> np.array ([some list comprehension])
> mainly because list comprehensions are just so sweet.
> But I imagine this isn't particularly efficient.
Right. Using a generator and np.fromiter() will avoid the creation of the
intermediate list. Something like:
np.fromiter((i for i in range(x))) # use xrange for Python 2
> I wonder if numpy has a "better" way, and if not, maybe it would be a nice
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion