<jupyter_start><jupyter_text>Operations performed in numpy<jupyter_code>import numpy as np
a = np.arange(12)
a
print(np.ndim(a))<jupyter_output>1<jupyter_text>reshape():- it changes the arrangement of items by changing the order<jupyter_code>b = a.reshape(2,6)
b
print(b.ndim)<jupyter_output>2<jupyter_text>flatten()/ ravel():- it used for flattening, for converting n-dim to 1-d<jupyter_code>x1 = b.flatten()
x1
x2 = b.ravel()
x2
# now let's replace 1st element 0 with 100 in b
b[0][0] = 100
b
print(x1)  # flatten() is creating a copy
print(x2)  # ravel() is creating a view
print(np.may_share_memory(x1,b))   # flatten() is creating a copy
print(np.may_share_memory(x2,b))   # ravel() is creating a view
# flatten method takes a parameter called order, by default it's row major
print(b, "\n")
print(b.flatten(order="f"))
print(b.flatten(order="c"))<jupyter_output>[[100   1   2   3   4   5]
 [  6   7   8   9  10  11]] 

[100   6   1   7   2   8   3   9   4  10   5  11]
[100   1   2   3   4   5   6   7   8   9  10  11]<jupyter_text>Stacking:- several arrays can be stacked together along different axes np.vstack():- to stack arrays along vertical axisnp.hstack():- to stack arrays along horinzontal axis<jupyter_code>x1 = np.array([[1,2],[3,4]])
x2 = np.array([[5,6],[7,8]])
np.vstack((x1,x2))
np.hstack((x1,x2))<jupyter_output><empty_output><jupyter_text>Matrix operations<jupyter_code>x1 = np.array([[1,2],[3,4],[5,6]])
x2 = np.array([5,6])
print(x1,"\n")
print(x2)
# addition of matrices
print(np.add(x1,x2), "\n")
print(x1+x2)
# subtraction of matrices
print(np.subtract(x1,x2), "\n")
print(x1-x2)
# element wise multiplication
print(np.multiply(x1,x2))
# matrix multiplication
print(np.dot(x1,x2))<jupyter_output>[17 39 61]
{'fraction_non_alphanumeric': 0.15504322766570605, 'fraction_numerical': 0.06743515850144093, 'mean_word_length': 4.7105263157894735, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '32969', 'license': 'MIT', 'n_tokens_mistral': 767, 'n_tokens_neox': 724, 'n_words': 181, 'path': 'Numpy/numpy operations.ipynb', 'repo_name': 'Mithun162001/Python-Notebooks', 'size': '1735'}