[Numpy-discussion] size of arrays

Todd toddrjen at gmail.com
Sat Mar 13 16:05:11 EST 2021


Ideally float64 uses 64 bits for each number while float16 uses 16 bits.
64/16=4.  However, there is some additional overhead.  This overhead makes
up a large portion of small arrays, but becomes negligible as the array
gets bigger.

On Sat, Mar 13, 2021, 16:01 <klark--kent at yandex.ru> wrote:

> Dear colleagues!
>
> Size of np.float16(1) is 26
> Size of np.float64(1) is 32
> 32 / 26 = 1.23
>
> Since memory is limited I have a question after this code:
>
>    import numpy as np
>    import sys
>
>    a1 = np.ones(1, dtype='float16')
>    b1 = np.ones(1, dtype='float64')
>    div_1 = sys.getsizeof(b1) / sys.getsizeof(a1)
>    # div_1 = 1.06
>
>    a2 = np.ones(10, dtype='float16')
>    b2 = np.ones(10, dtype='float64')
>    div_2 = sys.getsizeof(b2) / sys.getsizeof(a2)
>    # div_2 = 1.51
>
>    a3 = np.ones(100, dtype='float16')
>    b3 = np.ones(100, dtype='float64')
>    div_3 = sys.getsizeof(b3) / sys.getsizeof(a3)
>    # div_3 = 3.0
> Size of np.float64 numpy arrays is four times more than for np.float16.
> Is it possible to minimize the difference close to 1.23?
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210313/88edb3c8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 23474 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210313/88edb3c8/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 23474 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210313/88edb3c8/attachment-0003.png>


More information about the NumPy-Discussion mailing list