[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Numpy slower than Numeric
Lenard Lindstrom wrote:
Check out the types of array and alphaarray in TestNumpy(). Very
informative. They are both Numeric arrays. All that is accomplished is
that numpy.clip is called on one. It probably just treats it as an
iterable.
Interesting. If I convert to numpy arrays specifically however, I get an
error on 'pygame.surfarray.blit_array' of "TypeError: argument 2 must be
array, not numpy.ndarray" This error disappears when I convert the numpy
array back to a Numeric array before blitting tho.
So - what does this mean for Pygame? It appears to me there is no good
reason to use numpy, if you have to convert to/from Numeric arrays to
get it to work right anyway.
--Kamilche
def TestNumpy():
global pic2
pic2 = GetPic()
print 'numpy version: %s' % numpy.__version__
array = numpy.array(pygame.surfarray.pixels3d(pic2).astype(numpy.int))
alphaarray =
numpy.array(pygame.surfarray.pixels_alpha(pic).astype(numpy.unsignedinteger))
starttime = time.time()
for i in range(10):
array[:, :] = numpy.clip(array + [20, 0, 0], 0, 255)
numericarray = Numeric.array(array).astype(Numeric.Int)
pygame.surfarray.blit_array(pic2, numericarray)
numericarray = Numeric.array(alphaarray).astype(Numeric.UInt8)
pygame.surfarray.pixels_alpha(pic2)[:, :] = numericarray
Update()
print 'numpy time: %f seconds' % (time.time() - starttime)