<jupyter_start><jupyter_text>Dot Product<jupyter_code># 1st method
np.sum(a1*a2)
# 2nd method
(a1*a2).sum()
# 3rd method
dot=0
for i,j in zip(a1,a2):
    dot+=i*j
print(dot)
# 4th method
np.dot(a1,a2)
a1.dot(a2)
a2.dot(a1)<jupyter_output><empty_output><jupyter_text>mode of matrix or<jupyter_code>amag=np.sqrt((a1*a1).sum())
amag
amagb=np.linalg.norm(a1)
amag
cosangle=(a1*a2).sum()/(np.linalg.norm(a1)*np.linalg.norm(a2))
cosangle
angle=np.arccos(cosangle)
angle<jupyter_output><empty_output><jupyter_text>Speed Comparision<jupyter_code>from datetime import datetime as dt
a=np.random.randn(100)
b=np.random.randn(100)
T=100000

def slow_ab(a,b):
    result=0
    for i,j in zip(a,b):
        result+=i*j
    return result
t0=dt.now()
for t in range(T):
    slow_ab(a,b)
dt1=dt.now()-t0

t0=dt.now()
for t in range(T):
    a.dot(b)
dt2=dt.now()-t0

print('dt1/dt2 : ',dt1/dt2)
dt1.total_seconds()/dt2.total_seconds()<jupyter_output><empty_output><jupyter_text>vectors and matrices<jupyter_code>l=[[1,2,3],[4,5]]
m=np.array(l)
l[0][0]
l[0,0]
m[0][0]
m[0,0]
l
m
M=np.matrix(l)
M
a=np.array(M)
a
a.T
# 
np.zeros(10)
np.zeros((10,10))
np.ones(10)
np.ones((10,10))
np.random.random(10)
np.random.random((10,10))
np.random.random((10,10)).mean()
np.random.random((10,10)).sum()<jupyter_output><empty_output><jupyter_text>Matrix<jupyter_code>import numpy as np
dir(np.linalg)
a=[[1,3],[4,6]]
an=np.linalg.inv(a)
a
an
np.dot(a,an)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20233998623537508, 'fraction_numerical': 0.06331727460426703, 'mean_word_length': 6.494845360824742, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '309794', 'license': 'MIT', 'n_tokens_mistral': 768, 'n_tokens_neox': 736, 'n_words': 99, 'path': 'Udemy/Numpy.ipynb', 'repo_name': 'Dhaneshgupta1027/Python', 'size': '1453'}