Overflow error when mixing numpy arrays and regular python 2.7 arrays -


i'm having trouble understanding type conversions occur when try put data numpy array regular python array. figured out enough generate minimal example reproduces error:

import numpy import array  array_l = array.array('l', [0xff000000])  numpy_l = numpy.array([1], dtype='l')  #this code raises , overflow #overflowerror: python int large convert c long array_l[0] += numpy_l[0] 

why final line ever convert intermediate value c long? shouldn't use c unsigned long?

from python array documentation, type 'l' corresponds unsigned long of @ least 32 bits. element in numpy_l array has type numpy.uint32. realize these not same type, have expected compatible. if addition performed using unsigned long integers, there no overflow.

if perform same calculation using numpy arrays, or standard library arrays, have no issues. however, whole purpose of code take large numpy array , reformat use different object.

i can fix problem using explicit cast python long integer, it's slow. actual application has inside 5 loops arrays of length 10,000 or so.

#works, slow array_l[0] += long(np_l[0]) 

thanks!


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -