В настоящее время я использую обходной путь , который дает мне результаты типа
np.ndarray of shape (5, 11)
---
dtype: float64
contains non-finite elements: nan, inf
---
mean: 8.375849056603775
min: 0.0
max: 16.74
---
std: 4.9867932880730885
mad: 6.434493628314312
---
values:
[[ 0. 0.31 0.62 0.93 1.24 1.55 1.86 2.17 2.48 2.79 3.1 ]
[ 3.41 3.72 4.03 4.34 4.65 4.96 5.27 inf 5.89 6.2 6.51]
[ 6.82 7.13 7.44 7.75 8.06 8.37 8.68 8.99 9.3 9.61 9.92]
[10.23 10.54 nan 11.16 11.47 11.78 12.09 12.4 12.71 13.02 13.33]
[13.64 13.95 14.26 14.57 14.88 15.19 15.5 15.81 16.12 16.43 16.74]]
Это код:
import numpy as np
from statsmodels.robust import mad
def ndarray_info(arr, verbose=2):
"""returns extensive information about an np.ndarray as string"""
finArr = arr.flatten()
finArr = finArr[np.isfinite(finArr)]
info = ''
info += f'np.ndarray of shape {arr.shape}\n'
info += '\t---\n'
info += f'\tdtype: {arr.dtype}\n'
info += f'\tcontains non-finite elements: '
nonFinElLst = []
if np.isnan(arr).any():
nonFinElLst += ['nan']
if np.isinf(arr).any():
nonFinElLst += ['inf']
if len(nonFinElLst) > 0:
info += ', '.join(nonFinElLst) + '\n'
else:
info += '--\n'
info += '\t---\n'
info += f'\tmean: {np.mean(finArr)}\n'
info += f'\tmin: {np.min(finArr)}\n'
info += f'\tmax: {np.max(finArr)}\n'
if verbose >=1:
info += '\t---\n'
info += f'\tstd: {np.std(finArr)}\n'
info += f'\tmad: {mad(finArr)}\n'
if verbose >=2:
info += '\t---\n'
info += 'values:\n' + str(arr) + '\n'
return info
arr= np.arange(0,17,.31).reshape(5,11)
arr[3,2] = np.nan
arr[1,7] = np.inf
print(ndarray_info(arr))