<jupyter_start><jupyter_text>basic aggregate function for ndarray<jupyter_code>import numpy as np
print(f'numpy version = {np.__version__}')<jupyter_output>numpy version = 1.14.5<jupyter_text>1-dim array<jupyter_code>w=np.array([70, 48, 52, 60, 52])
w
w.size
np.min(w)
np.max(w)
np.sum(w)
np.mean(w)
np.median(w)
np.sort(w)<jupyter_output><empty_output><jupyter_text>use scipy.stats to calculate mode<jupyter_code>from scipy import stats
m=stats.mode(w)
m
m[0]
m[0][0]
m[1]
m[1][0]
np.sort(w)
w
w2=np.sort(w)[::-1]
w2
w
w.sort() #inplace
w<jupyter_output><empty_output><jupyter_text>2-dim array<jupyter_code>a=np.reshape(np.arange(1, 21), (4, 5))
a
np.mean(a)
a.size
a.shape
np.mean(a[0])
np.mean(a[:, 1])
a
np.mean(a, axis=0)
np.sum(a, axis=0)
np.sum(a, axis=1)
np.std(a)
np.var(a)
np.ptp(a) # peak to peak
np.max(a) - np.min(a)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19557625145518046, 'fraction_numerical': 0.04074505238649592, 'mean_word_length': 6.678571428571429, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '637036', 'license': 'MIT', 'n_tokens_mistral': 456, 'n_tokens_neox': 438, 'n_words': 73, 'path': 'numpy_basic_agg_fn.ipynb', 'repo_name': 'R1SE23/learn_numpy', 'size': '859'}