= 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)) nasties
๐งพ View as a summary
Pretty printing
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
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'
=3)
np.set_printoptions(precisionprint(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]])
= np.load("mysteryman.npy")
image 1,100,100] = float('nan')
image[
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
= np.random.randn(2) + 1j*np.random.randn(2)
c print(lovely(c))
array([ 1.883-1.27j , -1.348+0.969j])
# Other weirs stuff
= np.array(["a", "b", "c"])
w print(lovely(w))
= np.array([{}, {"a": 1}, {"b": 2, "c": 3}])
z print(lovely(z))
array(['a', 'b', 'c'], dtype='<U1')
array([{}, {'a': 1}, {'b': 2, 'c': 3}], dtype=object)
= np.array([1, 2, 3])
i str(lovely(i)), "array[3] i64 xโ[1, 3] ฮผ=2.000 ฯ=0.816 [1, 2, 3]") test_eq(
= np.array([True, False, True])
i str(lovely(i)), 'array[3] bool xโ[False, True] ฮผ=0.667 ฯ=0.471 [True, False, True]') test_eq(