<jupyter_start><jupyter_text>Indexing, Slicing & Boolean arrays<jupyter_code>import numpy as np
n=[6,7,8]
n[:2] # slicing in python
n[-1]  # indexing access
a=np.array([6,7,8])
a[0:2]
a[-1]
ma=np.array([[1,2,3],[4,5,6],[7,8,9]])  # Multidimensional array
ma
ma[1,2]  #(1st row, 2nd column)
ma[0:2,2]    # 0 to 2nd rows, and 2nd index element
ma[-1]
ma[-1, 0:2]
ma[:,1:3]  # accessing columns.":" will go through all rows
ma # sort of table
for row in ma:   # iterate through rows
    print(row)
# Flatten the list and print every cell

for cell in ma.flat:   # flattening to 1D & iterate
    print(cell)
reshapeArray=np.arange(6).reshape(3,2)   # Taking 6 range and reshaping to 3,2 dimension
reshapeArray
reshapeArray2=np.arange(6,12).reshape(3,2) 
reshapeArray2
np.vstack((reshapeArray,reshapeArray2))    # touple argument to stack two numpy array stack # Vertical stack
np.hstack((reshapeArray,reshapeArray2))   #  Horizontal stack
new= np.arange(30).reshape(2,15)
new
np.hsplit(new,3)   # Horizonal split to 3 new array
result=np.hsplit(new,3)
result[0]
result[1]
 r=np.vsplit(new,2)   # Vertical split to 2 new array
 r[0]
r[1]
a= np.arange(12).reshape(3,4)
a
b= a > 4           # Using Boolean operation
b
a[b]    # It will only return true values of numpy array
a[b] = -1  # any element that greater than 4 (b=a>4), will be replace by -1
a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14098837209302326, 'fraction_numerical': 0.05450581395348837, 'mean_word_length': 4.464285714285714, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '24767', 'license': 'MIT', 'n_tokens_mistral': 576, 'n_tokens_neox': 549, 'n_words': 158, 'path': 'Numpy/3. Indexing, Slicing & Boolean arrays.ipynb', 'repo_name': 'Shaon2221/Learning-and-Experimenting_Data-Science', 'size': '1376'}