<jupyter_start><jupyter_text>**Numpy is a linear algebra library for Python, the reason it is so important for data science with python is that almost all the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks.** ***Numpy is also incredibly fast, as it has bindings to C libraries.***  1) O-D array<jupyter_code>import numpy as np
arr = np.array(42)
arr<jupyter_output><empty_output><jupyter_text>2) 1-D array<jupyter_code>arr1 = np.array([1, 2, 3, 4, 5])
arr1<jupyter_output><empty_output><jupyter_text>3) 2-D array<jupyter_code>arr2 = np.array([[1, 2, 3], [4, 5, 6]])
arr2<jupyter_output><empty_output><jupyter_text>4) 3-D array<jupyter_code>arr3 = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
arr3<jupyter_output><empty_output><jupyter_text>Check number of dimension<jupyter_code>a = np.array(42)
b = np.array([1, 2, 3, 4, 5])
c = np.array([[1, 2, 3], [4, 5, 6]])
d = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
a.ndim
b.ndim
c.ndim
d.ndim<jupyter_output><empty_output><jupyter_text>Access array elements  IN 1-D array<jupyter_code>arr4 = np.array([1, 2, 3, 4])
arr4[0]
arr4[2]
arr4[1],arr4[3]   #getting element at index 1 & 3<jupyter_output><empty_output><jupyter_text>IN 2-D array<jupyter_code>arr5 = np.array([[1,2,3,4,5], [6,7,8,9,10]])
arr5
arr5[0,1] #or 
arr5[1][2]   
arr5[0:2,2]
arr5[-1]<jupyter_output><empty_output><jupyter_text>IN 3-D array<jupyter_code>arr6 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr6
arr6[0, 1]
arr6[2,1:2]
arr6[-1,0:2]
arr6[:,1:3]<jupyter_output><empty_output><jupyter_text>Negative indexing<jupyter_code>arr7 = np.array([[1,2,3,4,5], [6,7,8,9,10]])
arr7
arr7[1, -1]<jupyter_output><empty_output><jupyter_text>Slicing  IN 1-D array<jupyter_code>import numpy as np
arr8 = np.array([1, 2, 3, 4, 5, 6, 7])
arr8
arr8[1:5]
arr8[4:]
arr8[:4]
arr8[-1]
arr8[-3:-1]<jupyter_output><empty_output><jupyter_text>Using step<jupyter_code>arr8[1:5:2]
arr8[::2]<jupyter_output><empty_output><jupyter_text>IN 2-D array<jupyter_code>arr9 = np.array([[1,2,3,4,5], [6,7,8,9,10]])
arr9[0,1:5]
arr9[1,0:5:2]
arr9[0:2, 1:4]<jupyter_output><empty_output><jupyter_text>Iterate through Array<jupyter_code>arr10 = np.array([[6,7,8],[1,2,3],[4,5,6]])
arr10
for row in arr10:
    print(row)
for cell in arr10.flat:
    print(cell)<jupyter_output>6
7
8
1
2
3
4
5
6<jupyter_text>Stacking<jupyter_code>a = np.arange(6).reshape(3,2)
b = np.arange(6,12).reshape(3,2)
a
b
np.vstack((a,b))               #vertical stacking
np.hstack((a,b))             # horizontal stacking<jupyter_output><empty_output><jupyter_text>Spliting<jupyter_code>c = np.arange(30).reshape(2,15)
c
rslt = np.hsplit(c,3)                # horizantally split into 3 different arrays
rslt
rslt[0]
rslt[1]
rslt[2]
rslt = np.vsplit(c,2)
rslt
rslt[0]
rslt[1]<jupyter_output><empty_output><jupyter_text>Indexing With Boolean<jupyter_code>a = np.arange(12).reshape(3,4)
a
b = d > 4              # will return true where element in b is greater than 4 else return false
b<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18401057152296002, 'fraction_numerical': 0.08424182358771061, 'mean_word_length': 6.20952380952381, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 65, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '295377', 'license': 'MIT', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1414, 'n_words': 273, 'path': 'NumPy/NumPy Array Creation, Indexing, Slicing, Stacking, Spliting.ipynb', 'repo_name': 'rahulhgdev/Data-Science', 'size': '3027'}