0

How could I get to know how large is an output of sime code which is shown in the cell of Jupyter ntb cell? Eg., if I have a plot:

import seaborn as sns
import numpy as np

sns.heatmap(np.arange(50).reshape(5,-1))

the size of the ntb file is 14 KB and using this approach I could determine the size without the output and/or always look at one cell (copy it out). But what if I want to know this from within the ntb? Ie how much space the output takes.

To be clear, I do not care about the actual size of the object, ie if I print an array, I do not care how much that array takes up, but rather how much takes up the text which is being printed out, by how much will the .ipynb file grow.

Thanks.

My Work
  • 2,143
  • 2
  • 19
  • 47
  • Just out of curiosity, why are you interested in the size of a notebook file? And running `!ls -alth ` and parsing the output might do the trick. – Unni Sep 21 '20 at 11:09
  • :) both out of curiosity and I that have a file which I need to keep below some size and since I have plots there and if I would need to remove some so that I know which to remove/hide. Because I would want to hide as least as possible but enough. BTW that does not work for me, at least not in Windows (gives that `ls` is not recognised, need to be with `%`) – My Work Sep 21 '20 at 11:31
  • `ls` is a unix command. So it will not work on a windows shell. Perhaps [this](https://stackoverflow.com/questions/483864/windows-command-for-file-size-only) discussion can be useful. Sorry! I don't have a windows machine to test it out. – Unni Sep 21 '20 at 12:02
  • Ah, I see now where the problem is - we speak about different things. `%ls -alth ` works fine for me but gives me the size of the file, not of an individual cell/output of a cell in jupyter. – My Work Sep 21 '20 at 13:21
  • 1
    Run it before and after a cell and subtract the sizes :-) – Unni Sep 21 '20 at 13:55
  • Yes, that is exactly what I did not want to do and wanted to avoid :D. That is the point of the question, if that is possible to do from within jupyter or without this quite expensive "cheat" – My Work Sep 21 '20 at 14:56
  • Related: https://stackoverflow.com/questions/2104080/how-can-i-check-file-size-in-python – Unni Sep 21 '20 at 15:17

0 Answers0