Type Compatibility (In)?

In Numpy, I tried the following. I suspect this is not a mistake. In case this is a feature, I do not understand. Can anyone explain this? Thanks.

>>> np.array([173], dtype = np.uint8) * [360] array([62280]) >>> np.array([173], dtype = np.uint8) * 360 array([-3256], dtype=int16) >>> 
+5
source share
1 answer

The difference between these outputs is probably caused by an error in your numpy version.

The code

 np.array([173], dtype = np.uint8) * [360] 

is an abbreviation for:

 np.array([173], dtype = np.uint8) * np.array([360]) # output array([62280]) 

Thus, [360] is converted to a numpy array with dtype = int. Multiplication takes the highest precision and therefore returns an array with precision int.

+1
source

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


All Articles