<jupyter_start><jupyter_text>NumPy [Documentation](https://numpy.org/doc/)Installation using pip package installer and terminal:`pip install numpy`<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>NumPy Array & Matrix<jupyter_code># NumPy array
a_list = [1,2,3,4]
x = np.array(a_list)
type(x)
# NumPy matrix
a_matrix = [[1,2,3], [1,2,3], [1,2,3]]
y = np.array(a_matrix)
type(y)
# NumPy range
np.arange(0,5)
np.arange(1,11,2)
# NumPy array of zeros
np.zeros(3)
# NumPy matrix of zeros
np.zeros((5,5))
# NumPy array of ones
np.ones(3)
# Numpy matrix of ones
np.ones((5,5))
# NumPy array of linearly spaced points
np.linspace(0,20,41)
# NumPy identity matrix
np.eye(4)<jupyter_output><empty_output><jupyter_text>NumPy Random<jupyter_code># NumPy random return a sample from uniform distribution
np.random.rand(3)
np.random.rand(5,4)
# NumPy random return a sample from standard distribution
np.random.randn(5)
np.random.randn(5,4)
np.random.randint(1,100,10)
arr  = np.arange(25)
ranarr = np.random.randint(0,50,10)
arr.shape
# Reshape an array into a matrix
arr.reshape(5,5)
arr.reshape(5,5).shape
arr.dtype
ranarr.max()
# Index of the max value
ranarr.argmax()<jupyter_output><empty_output><jupyter_text>Numpy Operations<jupyter_code># Sum and deduction 
arr = np.arange(10)
arr
arr + arr
# Sum of rows of matrix
mat = np.arange(1,26).reshape(5,5)
np.sum(mat,1)
# Sum of columns of matrix
np.sum(mat,0)
# Multiplication
arr * arr
# devision
arr / arr
1 / arr
# Power
arr ** arr
# Square root
np.sqrt(arr)
# Exponential
np.exp(arr)
# Maximum
np.max(arr)
# Sin
np.sin(arr)
# Logarithm
np.log(arr)
# Standard deviation
np.std(arr)<jupyter_output><empty_output><jupyter_text>NumPy Indexing & Broadcasting<jupyter_code>arr = np.random.randint(0,100,10)
arr
# Array indexing
arr[8]
arr[1:5]
# Array broadcasting
arr_slice = arr[0:5]
arr_slice [:] = 100
arr
# Broadcasting changes the array itself, copy the array before broadcasting if the original is required
arr = np.random.randint(1,100,10)
arr_copy = arr.copy()
arr_copy
arr_slice = arr_copy[0:5]
arr_slice[:] = 200
arr_copy
# Matrix indexing
mat = np.array([[23,123,564],[756,952,165],[323,745,256]])
mat
mat[0]
mat[1][1]
mat[1,1]
mat[1:,1:]
# Conditional selection
arr = np.arange(1,11)
arr
arr > 5
bool_arr = arr > 5
arr[bool_arr]
arr[arr > 5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1451063829787234, 'fraction_numerical': 0.05446808510638298, 'mean_word_length': 6.081325301204819, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 24, 'https://': 1, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '23413', 'license': 'MIT', 'n_tokens_mistral': 1024, 'n_tokens_neox': 958, 'n_words': 219, 'path': 'notebooks/numpy.ipynb', 'repo_name': 'rmanaem/pydatasci', 'size': '2350'}