= 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 | typing.Union[numpy.ndarray, numpy.generic] | 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 | typing.Optional[bool] | 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])
= np.array([1, 2, 3])
i str(lovely(i)), "array[3] i64 x∈[1, 3] μ=2.000 σ=0.816 [1, 2, 3]") test_eq(
repr=lovely, str=None) set_config(
1,2,3]) np.array([
array[3] i64 x∈[1, 3] μ=2.000 σ=0.816 [1, 2, 3]