Change language

# numpy.dot () in Python

| |

numpy.dot (vector_a, vector_b, out = None) returns the point product of vectors a and b. It can handle two-dimensional arrays, but treats them like a matrix and does matrix multiplication. For N measurements, this is the sum of the products along the last a axis and the second longest b:

dot (a, b) [i, j, k, m] = sum (a [i, j, :] * b [k,:, m])

Parameters —

1. vector_a: [array_like], if a is complex, its complex conjugate is used to compute the dot product.
2. vector_b: [array_like], if b is complex, its complex conjugate used to compute the dot product.
3. out: [array, optional] The output argument must be C-contiguous and its dtype must be the dtype that will be returned for dot (a, b).

Return —

Dot product of vectors a and b. if vector_a and vector_b are 1D then scalar is returned

Code 1 —

 # Program Python illustrating # numpy.dot () method   import numpy as geek    # Scalars product = geek.dot ( 5 , 4 ) print ( " Dot Product of scalar values : " , product)   # 1D array vector_a = 2 + 3j vector_b = 4 + 5j    product = geek.dot (vector_a, vector_b) print ( "Dot Product :" , product)

Exit —

Dot Product of scalar values: 20 Dot Product: (-7 + 22j)

How does Code1 work?
vector_a = 2 + 3j
vector_b = 4 + 5j

is now a dot product
= 2 (4 + 5j) + 3j (4 — 5j)
= 8 + 10j + 12j — 15
= -7 + 22j

Code 2 —

 # Program Python illustrating # numpy.dot () method   import numpy as geek    # 1D array vector_a = geek.array ([[ 1 , 4 ], [ 5 , 6 ]]) vector_b = geek.array ([[ 2 , 4 ], [ 5 , 2 ]])   product = geek.dot (vector_a, vector_b) print ( "Dot Product :" , product)    product = geek.dot ( vector_b, vector_a) print ( " Dot Product : " , product)    "" " Code 2: as normal matrix multiplication "" "

Exit —

Dot Product: [[22 12] [40 32]] Dot Product: [[22 32] [15 32]]

https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.dot.html
,

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

NUMPYNUMPY

glob exclude pattern

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

NUMPYNUMPY

Python CSV error: line contains NULL byte

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries