Subtracting numpy 3D arrays in Python Vs Matlab

I have two numpy 3D arrays and I would like to know the difference between them.

>>>A.dtype
dtype('uint32')
>>>B.dtype
dtype('uint32')
>>>A.shape
(86, 50, 108)
>>>B.shape
(86, 50, 108)    
>>>A.min()
0
>>>B.min()
0
>>>A.max()
89478487
>>>B.max()
89115767

Now if we do A - B

>>> diff = abs( A-B );
>>> diff.min()
0
>>> diff.max()
4294967292

Given the importance minand maxboth matrices, we can not have 4294967292the maximum value of the difference matrix. I also performed similar operations in Matlab, and the difference diffand maximum value are diff.max()consistent. What is an operation A-B? My understanding is that the default behavior for adding, subtracting, multiplying and splitting arrays with each other was elementary, but there is something funny here.

+4
source share
2 answers

32- ints . ,

>>> numpy.uint32(0) - numpy.uint32(1)
4294967295

int...

>>> A = numpy.array([0,1,2],'uint32')
>>> B = numpy.array([1,2,3],'uint32')
>>> A-B
array([4294967295, 4294967295, 4294967295], dtype=uint32)
>>> A = A.astype(int)
>>> B = B.astype(int)
>>> A-B
array([-1, -1, -1])
+4

ints ( , ). , ?

diff = abs( A.astype('int32') - B.astype('int32') )

, Matlab: becuase, int Matlab . (Matlab):

>> uint32(4)-uint32(5)

ans =

0

4294967295, python.
, Matlab,

 >>> A = numpy.array([ 1,2,3], dtype='uint32')
 >>> B = numpy.array([2,2,2], dtype='uint32')
 >>> numpy.clip( A.astype(int) - B.astype(int), 0, numpy.iinfo(int).max )
 array([0, 0, 1])
+3

Source: https://habr.com/ru/post/1547032/


All Articles