I would like to welcome everyone to the first installment of what we are calling Snake_Bytes just a little nibble of some #Python snippets. Various developers from @PokitDokDev will be contributing on a weekly basis just to give you added venom in your coding skills. So let's begin with the first one:
I am continually asked how one gets started with #data-science other than putting a hashtag in a Twitter stream or getting a recommendation on it via LinkedIn. Almost all operations within machine learning start with the Dot Product or Scalar Product.
In vector calculus the dot product of two vectors in R is defined to be a number, for example if you have:
two vectors A = [A1, A2, ..., An] and B = [B1, B2, ..., Bn] is defined as:
There is also a Geometric whereas in Euclidean space, a Euclidean vector is a geometrical object that possesses both a magnitude and a direction. A vector can be pictured as an arrow. Its magnitude is its length, and its direction is the direction that the arrow points. The magnitude of a vector A is denoted by . The dot product of two Euclidean vectors A and B is defined by[
where θ is the angle between A and B.
In particular, if A and B are orthogonal, then the angle between them is 90° and
At the other extreme, if they are codirectional, then the angle between them is 0° and
This implies that the dot product of a vector A by itself is
which is the formula for the Euclidean length of the vector.
So what does this actually do for me? I think its time to code something already!
There are several different ways to approach the coding. Actually it is really simple:
def dot_product (u,v):
return sum(u[i] * v[i] for i in range(len(u))])
return sum ([a*b) for (a,b) in zip(u,v)])
The advantage in the latter using the zip() is that it does the lifting for you and makes an iterator that aggregates elements from each of the iterables.
The dot product can be used in several applications ranging from audio, text, and similarity to graphics rendering. In fact, many machine learning algorithms can be expressed entirely in terms of dot products.
So there is the first Snake_Byte.
Hopefully it wasn't too painful.
- Why PokitDok Joined Hyperledger - June 26, 2018
- Full Consensus and Distributed Ledger Hardware Acceleration - May 10, 2017
- Blockchain Virtual Machines with Consensus in Silicon - October 11, 2016
- Snake_Bytes #3: Statistics! - September 23, 2016
- DokChain Technical Deep Dive - Part One - September 13, 2016
- Welcome To Snake_Bytes - September 9, 2016
- The DokChain is Now - July 13, 2016
- PokitDok Now in the Microsoft Azure Marketplace - June 8, 2016
- ClearingHouses Are Oxymorons - May 4, 2016
- Social Capital Within Social Health Networks (part 2) - August 22, 2012