Re: [Numpy-discussion] List comprehension and loops performances with NumPy arrays

2017-10-10 Thread Chris Barker - NOAA Federal
Andrea, One note: transposing is almost free — it just rearranges the strides — I.e. changed how the array is interpreted. It doesn’t actually move the data around. -CHB Sent from my iPhone On Oct 7, 2017, at 2:58 AM, Andrea Gavana wrote: Apologies, correct timeit code this time (I had gotten

Re: [Numpy-discussion] List comprehension and loops performances with NumPy arrays

2017-10-08 Thread Andrea Gavana
On Sat, 7 Oct 2017 at 16.59, Nicholas Nadeau wrote: > Hi Andrea! > > Checkout the following SO answers for similar contexts: > - > https://stackoverflow.com/questions/22108488/are-list-comprehensions-and-functional-functions-faster-than-for-loops > - > https://stackoverflow.com/questions/30245397

Re: [Numpy-discussion] List comprehension and loops performances with NumPy arrays

2017-10-07 Thread Nicholas Nadeau
Hi Andrea! Checkout the following SO answers for similar contexts: - https://stackoverflow.com/questions/22108488/are-list-comprehensions-and-functional-functions-faster-than-for-loops - https://stackoverflow.com/questions/30245397/why-is-list-comprehension-so-faster To better visualize the issue

Re: [Numpy-discussion] List comprehension and loops performances with NumPy arrays

2017-10-07 Thread Andrea Gavana
Apologies, correct timeit code this time (I had gotten the wrong shape for the output matrix in the loop case): if __name__ == '__main__': repeat = 1000 items = [Item('item_%d'%(i+1)) for i in xrange(500)] output = numpy.asarray([item.do_something() for item in items]).T statemen

[Numpy-discussion] List comprehension and loops performances with NumPy arrays

2017-10-07 Thread Andrea Gavana
Hi All, I have this little snippet of code: import timeit import numpy class Item(object): def __init__(self, name): self.name = name self.values = numpy.random.rand(8, 1) def do_something(self): sv = self.values.sum(axis=0) array = numpy.empty((8,