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--k...@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@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to