lovely-numpy
  1. ✨ Misc
  2. πŸ€” Config
  • πŸ’Ÿ Lovely NumPy
  • πŸ”Ž Array Representations
    • 🧾 View as a summary
    • πŸ–ŒοΈ View as RGB images
    • πŸ“Š View as a histogram
    • πŸ“Ί View channels
  • πŸ–ΌοΈ Image utils
    • 🎨 color mapping
    • πŸ”² Pad and frame
    • 🏁 Image grid
  • ✨ Misc
    • πŸ‘οΈ Lo and behold!
    • 🎭 Matplotlib integration
    • πŸ€” Config

On this page

  • Defaults:
  • set_config
  • get_config
  • config
  • Examples
    • Precision
    • Scientific mode
    • Color on/off
    • In-memory size of data
    • Verbose by default
    • Reser to defaults
    • Context manager
    • Matplotlib and seed
  1. ✨ Misc
  2. πŸ€” Config

πŸ€” Config

Defaults:

Type Default Details
precision int 3 Digits after .
threshold_max int 3 .abs() larger than 1e3 -> Sci mode
threshold_min int -4 .abs() smaller that 1e-4 -> Sci mode
sci_mode NoneType None Sci mode (2.3e4). None=auto
show_mem_above int 1024 Show memory usage in b/Kb/Mb/Gb if it’s larger than this
indent int 2 Indent for .deeper()
color bool True ANSI colors in text
verbose bool False Show the default repr by default
deeper_width int 9 For .deeper, width per level
plt_seed int 42 Sampling seed for plot
fig_close bool True Close matplotlib Figure
fig_show bool False Call plt.show() for .plt, .chans and .rgb

source

set_config

 set_config (precision:Union[~Default,int,NoneType]=Ignore,
             threshold_min:Union[~Default,int,NoneType]=Ignore,
             threshold_max:Union[~Default,int,NoneType]=Ignore,
             sci_mode:Union[~Default,bool,NoneType]=Ignore,
             show_mem_above:Union[~Default,bool,NoneType]=Ignore,
             indent:Union[~Default,bool,NoneType]=Ignore,
             color:Union[~Default,bool,NoneType]=Ignore,
             verbose:Union[~Default,bool,NoneType]=Ignore,
             deeper_width:Union[~Default,int,NoneType]=Ignore,
             repr:Union[~Default,Callable,NoneType]=Ignore,
             str:Union[~Default,Callable,NoneType]=Ignore,
             plt_seed:Union[~Default,int,NoneType]=Ignore,
             fig_close:Union[~Default,bool,NoneType]=Ignore,
             fig_show:Union[~Default,bool,NoneType]=Ignore)

Set config variables


source

get_config

 get_config ()

Get a copy of config variables


source

config

 config (precision:Union[~Default,int,NoneType]=Ignore,
         threshold_min:Union[~Default,int,NoneType]=Ignore,
         threshold_max:Union[~Default,int,NoneType]=Ignore,
         sci_mode:Union[~Default,bool,NoneType]=Ignore,
         show_mem_above:Union[~Default,bool,NoneType]=Ignore,
         indent:Union[~Default,bool,NoneType]=Ignore,
         color:Union[~Default,bool,NoneType]=Ignore,
         verbose:Union[~Default,bool,NoneType]=Ignore,
         deeper_width:Union[~Default,int,NoneType]=Ignore,
         repr:Union[~Default,Callable,NoneType]=Ignore,
         str:Union[~Default,Callable,NoneType]=Ignore,
         plt_seed:Union[~Default,int,NoneType]=Ignore,
         fig_close:Union[~Default,bool,NoneType]=Ignore,
         fig_show:Union[~Default,bool,NoneType]=Ignore)

Context manager for temporarily setting config options

Examples

from lovely_numpy import lo, lovely, set_config, get_config, config

Precision

set_config(precision=5)
lo(np.array([1., 2, 3]))
array[3] x∈[1.00000, 3.00000] ΞΌ=2.00000 Οƒ=0.81650 [1.00000, 2.00000, 3.00000]

Scientific mode

set_config(sci_mode=True) # Force always on
lo(np.array([1., 2, 3]))
array[3] x∈[1.00000e+00, 3.00000e+00] ΞΌ=2.00000e+00 Οƒ=8.16497e-01 [1.00000e+00, 2.00000e+00, 3.00000e+00]

Color on/off

set_config(color=False) # Force always off
lo(np.array(np.nan))
array NaN! nan

In-memory size of data

lo(np.array(np.ones((100))))
array[100] x∈[1.00000e+00, 1.00000e+00] ΞΌ=1.00000e+00 Οƒ=0.
set_config(show_mem_above=10)
lo(np.array(np.ones((100))))
array[100] 0.8Kb x∈[1.00000e+00, 1.00000e+00] ΞΌ=1.00000e+00 Οƒ=0.

Verbose by default

set_config(verbose=True)
lo(np.ones(100, dtype=np.int8))
array[100] i8 100b x∈[1, 1] ΞΌ=1.00000e+00 Οƒ=0.
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int8)

Reser to defaults

set_config(precision=None, sci_mode=None, color=None, show_mem_above=1024, verbose=None)
lo(np.array([1., 2, np.nan]))
array[3] ΞΌ=1.500 Οƒ=0.500 NaN! [1.000, 2.000, nan]
np.array([1,2])
array([1, 2])

Context manager

with config(sci_mode=True):
    print(lo(np.array([1., 2, 3])))
array[3] x∈[1.000e+00, 3.000e+00] ΞΌ=2.000e+00 Οƒ=8.165e-01 [1.000e+00, 2.000e+00, 3.000e+00]
lo(np.array([1., 2, 3]))
array[3] x∈[1.000, 3.000] ΞΌ=2.000 Οƒ=0.816 [1.000, 2.000, 3.000]

Matplotlib and seed

a = np.random.default_rng(seed=1).normal(size=1000)
_ = lo(a).plt() # The figure was closed, it will not be displayed
set_config(fig_close=False)
_ = lo(a).plt() # figure was not closed. All figures that are not closed are displayed after the cell runs.

For performance reasons, .plt will randomly sample up tp max_s elements from the data (10k be default).

You can change the seed used for this sampling (42 by default):

set_config(plt_seed=1)
lo(a).plt(max_s=100)

set_config(plt_seed=2)
lo(a).plt(max_s=100)

More details in matplotlib