Python Forum
Numpy library working out cosine.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy library working out cosine.
#1
import numpy as np

a = np.array([1, 2])
b = np.array([2, 1])

dot = 0

cosangle = a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(cosangle)
So I'm following a tutorial and the guy doesn't explain allot in terms of why this actually gives
the value of the cosine. Please Help.
Reply
#2
This is the first formula in the Geometric Definition section in the wikipedia page about the dot product.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 540 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,602 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,976 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  Numpy install using pip not working w/37 allnotes 2 4,042 Aug-08-2018, 07:52 PM
Last Post: allnotes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020