Sometimes, one simple solution uses a custom type for your matrix elements. Based on the range of numbers you need, you can use the dtype manual dtype and especially less for your products. Since Numpy considers the largest object type by default, this can be a useful idea in many cases. Here is an example:
In [70]: a = np.arange(5) In [71]: a[0].dtype Out[71]: dtype('int64') In [72]: a.nbytes Out[72]: 40 In [73]: a = np.arange(0, 2, 0.5) In [74]: a[0].dtype Out[74]: dtype('float64') In [75]: a.nbytes Out[75]: 32
And with a custom type:
In [80]: a = np.arange(5, dtype=np.int8) In [81]: a.nbytes Out[81]: 5 In [76]: a = np.arange(0, 2, 0.5, dtype=np.float16) In [78]: a.nbytes Out[78]: 8
KasrΓ’mvd 03 Oct '16 at 22:09 2016-10-03 22:09
source share