getsizeof
has limited value. It can be way off for lists. For arrays it's better, but you have to understand how arrays are stored.
In [447]: import sys
In [448]: a = np.arange(100)
In [449]: sys.getsizeof(a)
Out[449]: 896
But look at the size
of a view
:
In [450]: b = a.reshape(10,10)
In [451]: sys.getsizeof(b)
Out[451]: 112
This shows the size of the array object, but not the size of the shared databuffer. b
doesn't have its own databuffer.
In [453]: a.size
Out[453]: 100
In [454]: b.size
Out[454]: 100
So my guess is that your a
and b
are views of some other arrays. But the concatenate produces a new array with its own databuffer. It can't be a view of the other two. So its getsizeof
reflects that.
In [457]: c = np.concatenate((a,b.ravel()))
In [459]: c.shape
Out[459]: (200,)
In [460]: c.size
Out[460]: 200
In [461]: sys.getsizeof(c)
Out[461]: 1696
The databuffer for a
is 100*8 bytes, so the 'overhead' is 96. For c
, 200*8, again with a 96 'overhead'.