<jupyter_start><jupyter_text>NumPyNumPy is the fundamental package for scientific computing with Python. It contains among other things:- a powerful N-dimensional array object- sophisticated (broadcasting) functions- tools for integrating C/C++ and Fortran code- useful linear algebra, Fourier transform, and random number capabilitiesBesides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.**Note:** NumPy stands for Numeric Python. It's easy, fast and allow calculations over entire arrays. Find more [here](http://www.numpy.org/)   Basic usage<jupyter_code># let's import library first
import numpy as np
# from Python list to Numpy array
python_list = [1.2, 3.4, 6, 99]
np_array = np.array(python_list)
print(np_array)
# add/substract/divide/multiply by scalar
np_array+4.5, np_array-4.5, np_array/4.5, np_array*4.5
# subsetting
np_array[np_array<3]
# shape of array
print(np_array.shape) # column vector
np.logical_and(np_array > 2, np_array < 20) # logical_or, logical_not is also available

# select result
print(np_array[np.logical_and(np_array > 2, np_array < 20)])
# for loop over 2D numpy array (https://docs.scipy.org/doc/numpy/reference/arrays.nditer.html#arrays-nditer)
for val in np.nditer(np.array([[1,2,3], [3,2,1]])):
    print(val)<jupyter_output>1
2
3
3
2
1<jupyter_text>Basic Statistics<jupyter_code># let's generate some data
data_points = np.random.randint(200, size=100)
data_points
np.mean(data_points), np.median(data_points), np.std(data_points), np.max(data_points), np.min(data_points)<jupyter_output><empty_output><jupyter_text>Matrices (2D Arrays)<jupyter_code># 2D array
np_array2D = np.array([[1,2,3], [3,2,1], [5,6,2]])
print(f'Our 2D array: \n {np_array2D}')
print(f'\nShape of 2D array is {np_array2D.shape}') # matrix

# slice 2D array
np_array2D_sliced = np_array2D[1:, :-1]
print(f'\nOur 2D array (first row and last column sliced): \n {np_array2D_sliced}')
# matrix multiplication 
A = np.random.randint(25, size=(3,3))
B = np.random.randint(45, size=(3,3))

print(f'A matrix : \n {A}')
print(f'\nB matrix : \n {B}')
print(f'\nA*B element-wise: \n {A*B}')
print(f'\nA*B matrix multiplication : \n {A.dot(B)}')<jupyter_output>A matrix : 
 [[ 0  1 23]
 [ 3  0 23]
 [ 5 24  5]]

B matrix : 
 [[34 17 19]
 [ 9  4 15]
 [35 42 28]]

A*B element-wise: 
 [[   0   17  437]
 [  27    0  345]
 [ 175 1008  140]]

A*B matrix multiplication : 
 [[ 814  970  659]
 [ 907 1017  701]
 [ 561  391  595]]
{'fraction_non_alphanumeric': 0.1322124570118456, 'fraction_numerical': 0.0573175391669851, 'mean_word_length': 4.869955156950673, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '513792', 'license': 'MIT', 'n_tokens_mistral': 1065, 'n_tokens_neox': 962, 'n_words': 284, 'path': 'Modules/1-Preparation/notebooks/intro_to_numpy.ipynb', 'repo_name': 'open-dse/into_to_ds_with_python', 'size': '2617'}