lovely-numpy
  1. ๐Ÿ”Ž Array Representations
  2. ๐Ÿงพ View as a summary
  • ๐Ÿ’Ÿ 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

  • Pretty printing
    • lovely
    • Examples
  1. ๐Ÿ”Ž Array Representations
  2. ๐Ÿงพ View as a summary

๐Ÿงพ View as a summary

Pretty printing


source

lovely

 lovely (x:Union[numpy.ndarray,numpy.generic], plain:bool=False,
         verbose:bool=False, depth:int=0, lvl:int=0,
         color:Optional[bool]=None)

Pretty-print the stats of a numpy array or scalar

Type Default Details
x Union The data you want to explore
plain bool False Plain old way
verbose bool False Both summaty and plain
depth int 0 Show deeper summary, up to depth
lvl int 0 Indentation level
color Optional None Override get_config().color
Returns str The summary

Examples

nasties = randoms[:12].copy()

nasties[0] *= 10000
nasties[1] /= 10000
nasties[3] = float('inf')
nasties[4] = float('-inf')
nasties[5] = float('nan')
nasties = nasties.reshape((2,6))
print(lovely(nasties))
array[2, 6] n=12 xโˆˆ[-0.151, 1.764e+04] ฮผ=1.960e+03 ฯƒ=5.544e+03 +Inf! -Inf! NaN!
print(lovely(randoms[0]))
print(lovely(randoms[:2]))
print(lovely(randoms[:6].reshape(2, 3))) # More than 2 elements -> show statistics
print(lovely(randoms[:11])) # More than 10 -> don't show values
1.764
array[2] ฮผ=1.082 ฯƒ=0.682 [1.764, 0.400]
array[2, 3] n=6 xโˆˆ[-0.977, 2.241] ฮผ=1.046 ฯƒ=1.090 [[1.764, 0.400, 0.979], [2.241, 1.868, -0.977]]
array[11] xโˆˆ[-0.977, 2.241] ฮผ=0.684 ฯƒ=0.938

Do we have any floating point nasties? Are the values all zeros?

# Statistics and range are calculated on good values only, if there are at lest 3 of them.
print(lovely(nasties))
array[2, 6] n=12 xโˆˆ[-0.151, 1.764e+04] ฮผ=1.960e+03 ฯƒ=5.544e+03 +Inf! -Inf! NaN!
print(lovely(nasties, color=False))
array[2, 6] n=12 xโˆˆ[-0.151, 1.764e+04] ฮผ=1.960e+03 ฯƒ=5.544e+03 +Inf! -Inf! NaN!
print(lovely(np.array([float("nan")]*11)))
array[11] NaN!
print(lovely(np.zeros(12, dtype=np.float16)))
print(lovely(np.array([], dtype=int)))
array[12] f16 all_zeros
array[0] i64 empty
str(lovely(np.array([], dtype=int)))
'array[0] i64 \x1b[38;2;127;127;127mempty\x1b[0m'
np.set_printoptions(precision=3)
print(lovely(nasties, verbose=True))
array[2, 6] n=12 xโˆˆ[-0.151, 1.764e+04] ฮผ=1.960e+03 ฯƒ=5.544e+03 +Inf! -Inf! NaN!
array([[ 1.764e+04,  4.002e-05,  9.787e-01,        inf,       -inf,
               nan],
       [ 9.501e-01, -1.514e-01, -1.032e-01,  4.106e-01,  1.440e-01,
         1.454e+00]])
print(lovely(nasties, plain=True))
array([[ 1.764e+04,  4.002e-05,  9.787e-01,        inf,       -inf,
               nan],
       [ 9.501e-01, -1.514e-01, -1.032e-01,  4.106e-01,  1.440e-01,
         1.454e+00]])
image = np.load("mysteryman.npy")
image[1,100,100] = float('nan')

print(lovely(image, depth=1))
array[3, 196, 196] f32 n=115248 (0.4Mb) xโˆˆ[-2.118, 2.640] ฮผ=-0.388 ฯƒ=1.073 NaN!
  array[196, 196] f32 n=38416 xโˆˆ[-2.118, 2.249] ฮผ=-0.324 ฯƒ=1.036
  array[196, 196] f32 n=38416 xโˆˆ[-1.966, 2.429] ฮผ=-0.274 ฯƒ=0.973 NaN!
  array[196, 196] f32 n=38416 xโˆˆ[-1.804, 2.640] ฮผ=-0.567 ฯƒ=1.178
# We don't really supposed complex numbers yet
c = np.random.randn(2) + 1j*np.random.randn(2)
print(lovely(c))
array([ 1.883-1.27j , -1.348+0.969j])
# Other weirs stuff

w = np.array(["a", "b", "c"])
print(lovely(w))

z = np.array([{}, {"a": 1}, {"b": 2, "c": 3}])
print(lovely(z))
array(['a', 'b', 'c'], dtype='<U1')
array([{}, {'a': 1}, {'b': 2, 'c': 3}], dtype=object)
i = np.array([1, 2, 3])
test_eq(str(lovely(i)), "array[3] i64 xโˆˆ[1, 3] ฮผ=2.000 ฯƒ=0.816 [1, 2, 3]")
i = np.array([True, False, True])
test_eq(str(lovely(i)), 'array[3] bool xโˆˆ[False, True] ฮผ=0.667 ฯƒ=0.471 [True, False, True]')