numpy.vdot() in Python (original) (raw)
Last Updated : 08 Mar, 2024
Prerequisite – numpy.dot() in Pythonnumpy.vdot(vector_a, vector_b)
returns the dot product of vectors a and b. If first argument is complex the complex conjugate of the first argument(this is where vdot()
differs working of dot()
method) is used for the calculation of the dot product. It can handle multi-dimensional arrays but working on it as a flattened array.
Parameters –
- vector_a : [array_like] if a is complex its complex conjugate is used for the calculation of the dot product.
- vector_b : [array_like] if b is complex its complex conjugate is used for the calculation of the dot product.
Return – dot Product of vectors a and b.
Code 1 :
import
numpy as geek
vector_a
=
2
+
3j
vector_b
=
4
+
5j
product
=
geek.vdot(vector_a, vector_b)
print
(
"Dot Product : "
, product)
Output :
Dot Product : (23-2j)
How Code1 works ?
vector_a = 2 + 3j
vector_b = 4 + 5j
As per method, take conjugate of vector_a i.e. 2 – 3j
now dot product = 2(4 – 5j) + 3j(4 – 5j)
= 8 – 10j + 12j + 15
= 23 – 2j
Code 2 :
import
numpy as geek
vector_a
=
geek.array([[
1
,
4
], [
5
,
6
]])
vector_b
=
geek.array([[
2
,
4
], [
5
,
2
]])
product
=
geek.vdot(vector_a, vector_b)
print
(
"Dot Product : "
, product)
product
=
geek.vdot(vector_b, vector_a)
print
(
"\nDot Product : "
, product)
Output :
Dot Product : 55
Dot Product : 55
Similar Reads
- numpy.var() in Python numpy.var(arr, axis = None) : Compute the variance of the given data (array elements) along the specified axis(if any). Example : x = 1 1 1 1 1 Standard Deviation = 0 . Variance = 0 y = 9, 2, 5, 4, 12, 7, 8, 11, 9, 3, 7, 4, 12, 5, 4, 10, 9, 6, 9, 4 Step 1 : Mean of distribution 4 = 7 Step 2 : Summat 3 min read
- numpy.std() in Python numpy.std() is a function provided by the NumPy library that calculates the standard deviation of an array or a set of values. Standard deviation is a measure of the amount of variation or dispersion of a set of values. [Tex]\text{Standard Deviation} = \sqrt{\text{mean} \left( (x - x.\text{mean}())^ 4 min read
- numpy.tri() in Python numpy.tri(R, C = None, k = 0, dtype = 'float') : Creates an array with 1's at and below the given diagonal(about k) and 0's elsewhere. Parameters : R : Number of rows C : [optional] Number of columns; By default R = C k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above 2 min read
- numpy.vstack() in python numpy.vstack() is a function in NumPy used to stack arrays vertically (row-wise). It takes a sequence of arrays as input and returns a single array by stacking them along the vertical axis (axis 0). Example: Vertical Stacking of 1D Arrays Using numpy.vstack() [GFGTABS] Python import numpy as geek a 2 min read
- numpy.rint() in Python The numpy.rint() is a mathematical function that rounds elements of the array to the nearest integer. Syntax : numpy.rint(x[, out]) = ufunc ‘rint’) Parameters : array : [array_like] Input array. Return : An array with all array elements being rounded off, having same type and shape as input. Code #1 2 min read
- numpy.zeros() in Python numpy.zeros() function creates a new array of specified shapes and types, filled with zeros. It is beneficial when you need a placeholder array to initialize variables or store intermediate results. We can create 1D array using numpy.zeros(). Let's understand with the help of an example: [GFGTABS] P 2 min read
- numpy.repeat() in Python The numpy.repeat() function repeats elements of the array - arr. Syntax : numpy.repeat(arr, repetitions, axis = None) Parameters : array : [array_like]Input array. repetitions : No. of repetitions of each array elements along the given axis. axis : Axis along which we want to repeat values. By defau 2 min read
- numpy.dot() in Python numpy.dot(vector_a, vector_b, out = None) returns the dot product of vectors a and b. It can handle 2D arrays but considers them as matrix and will perform matrix multiplication. For N dimensions it is a sum-product over the last axis of a and the second-to-last of b : dot(a, b)[i,j,k,m] = sum(a[i,j 2 min read
- numpy.eye() in Python numpy.eye() is a function in the NumPy library that creates a 2D array with ones on the diagonal and zeros elsewhere. This function is often used to generate identity matrices with ones along the diagonal and zeros in all other positions. Let's understand with the help of an example: [GFGTABS] Pytho 2 min read
- numpy.roots() function - Python numpy.roots() function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n] Syntax : numpy.roots(p) Parame 1 min read