I just started using numpy and figured out something strange happens. (i read the official Quickstart Tutorial but it didn't help) This is the code:
>>> jok = np.int16(33)
>>> jok.dtype
dtype('int16')
>>> jok += 1
>>> jok
34
>>> jok.dtype
dtype('int64')
When i apply arithmetic operations to a variable (jok) it changes the 'dtype' from 'int16' to 'int64'. But when i apply the same operations to arrays it stays the same, it doesn't change the 'dtype':
>>> ar = np.arange(6,dtype='int8')
>>> ar
array([0, 1, 2, 3, 4, 5], dtype=int8)
>>> ar += 10
>>> ar
array([10, 11, 12, 13, 14, 15], dtype=int8)
Why does this happens?
Is it possible to apply arithmetic operations to a variable like 'jok' and conserving the specifies 'dtype' of the variable (in my case 'int16')?
And why does it always change them to 'int64'. I know 'int64' is the default type of numpy, but i want to save some memory making the type of my variables smaller.
Are there any reasons for me to stay with 'int64' knowing that my maximum value will not even reach 1,000. Most of my variables will be below 200 ('jok' will always be < 400).