# Dot

How to find the dot product from two NumPy array.

#### New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.

You can set up Plotly to work in online or offline mode, or in jupyter notebooks.

We also have a quick-reference cheatsheet (new!) to help you get started!

```
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
```

#### Dot Product¶

To compute the `dot product`

of two NumPy arrays, we can do so with `np.dot()`

.

The dot product is a mathematical binary operation which takes, in the computer science case, two arrays of equal length and returns the sum of the pairwise products of the elements in the arrays. To provide clarity to this, if $A$ is an array $[a_1, a_2, ..., a_n]$ and $B$ is an array $[b_1, b_2, ..., b_n]$ both with length $n$, then the dot product is defined as:

$$ \begin{align*} a_1 \times b_1 + a_2 \times b_2 + ... + a_n \times b_n \end{align*} $$where $\times$ is just the multiplication operator.

```
array_a = np.array([2, 3, 0])
array_b = np.array([2, -1, 1])
np.dot(array_a, array_b)
```

#### Visualize as Vectors¶

We can think of these arrays as defining a vector with each value representing the magnitiude of along the x-axis, y-axis, etc. And the dot product can also be used as a metric for orthogonality between these vectors. In general terms, the larger the number, to more parallel the two vectors are. If the dot product returns $0$, this means the vectors point orthogonally.

We can plot the vectors defined above to get a sense for what the dot product means in that example:

```
import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter3d(
x=[0, array_a[0]],
y=[0, array_a[1]],
z=[0, array_a[2]],
mode='markers+lines',
name='array a',
marker=dict(
size=[12, 1]
)
)
trace2 = go.Scatter3d(
x=[0, array_b[0]],
y=[0, array_b[1]],
z=[0, array_b[2]],
mode='markers+lines',
name='array b',
marker=dict(
size=[12, 1]
)
)
data = [trace1, trace2]
layout = go.Layout(
title = 'Vector Representation of Arrays'
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='numpy-min')
```

```
help(np.dot)
```