Python memory usage of numpy arrays

前端 未结 3 1692
野趣味
野趣味 2020-11-28 04:16

I\'m using python to analyse some large files and I\'m running into memory issues, so I\'ve been using sys.getsizeof() to try and keep track of the usage, but it\'s behaviou

3条回答
  •  野性不改
    2020-11-28 04:46

    The field nbytes will give you the size in bytes of all the elements of the array in a numpy.array:

    size_in_bytes = my_numpy_array.nbytes
    

    Notice that this does not measures "non-element attributes of the array object" so the actual size in bytes can be a few bytes larger than this.

提交回复
热议问题