In my current job, I use Numpy and list methods many times, and in the interest of best performance, I have the following questions:
What actually happens behind the scenes if I create a Numpy array as follows?
a = numpy.array( [1,2,3,4] )
I assume that python first creates a regular list containing the values, then uses the size of the list to highlight the numpy array, and then copies the values ββto this new array. Is this correct, or is the interpreter smart enough to understand that the list is only intermediate and instead copy the values ββdirectly?
Similarly, if I want to create a numpy array from a list comprehension using numpy.fromiter ():
a = numpy.fromiter( [ x for x in xrange(0,4) ], int )
Will this result lead to an intermediate list of generated values ββbefore being sent to fromiter ()?
Regards Niels
performance python numpy
NielsGM Jan 17 '13 at 5:17 2013-01-17 05:17
source share