TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Dot Product

Linear Algebra
Easy

Compute the dot product of two equal-length vectors:

x⋅y=∑i=1nxiyix \cdot y = \sum_{i=1}^{n} x_i y_ix⋅y=i=1∑n​xi​yi​

Here, xix_ixi​ and yiy_iyi​ are corresponding vector elements and nnn is their shared length. Return the result as a Python float.

Loading visualization...

Examples

Input: x = [1, 2, 3], y = [4, 5, 6]

Output: 32.0

Explanation: The products 4, 10, and 18 sum to 32.

Input: x = [1, 0], y = [0, 1]

Output: 0.0

Input: x = [-1, 2], y = [3, -1]

Output: -5.0

Hint 1

Convert both vectors with np.asarray(..., dtype=float).

Hint 2

Use np.dot(x, y) and convert the NumPy scalar to float.

Requirements

  • Compute the dot product with NumPy
  • Return a Python float

Constraints

  • x and y are equal-length, nonempty one-dimensional numeric lists
  • Each vector contains at most 10610^6106 values
  • Use NumPy only
Try Similar Problems
Cosine SimilarityEuclidean DistanceMatrix TransposeMatrix TraceManhattan Distance

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Implement Dot Product

Linear Algebra
Easy

Compute the dot product of two equal-length vectors:

x⋅y=∑i=1nxiyix \cdot y = \sum_{i=1}^{n} x_i y_ix⋅y=i=1∑n​xi​yi​

Here, xix_ixi​ and yiy_iyi​ are corresponding vector elements and nnn is their shared length. Return the result as a Python float.

Loading visualization...

Examples

Input: x = [1, 2, 3], y = [4, 5, 6]

Output: 32.0

Explanation: The products 4, 10, and 18 sum to 32.

Input: x = [1, 0], y = [0, 1]

Output: 0.0

Input: x = [-1, 2], y = [3, -1]

Output: -5.0

Hint 1

Convert both vectors with np.asarray(..., dtype=float).

Hint 2

Use np.dot(x, y) and convert the NumPy scalar to float.

Requirements

  • Compute the dot product with NumPy
  • Return a Python float

Constraints

  • x and y are equal-length, nonempty one-dimensional numeric lists
  • Each vector contains at most 10610^6106 values
  • Use NumPy only
Try Similar Problems
Cosine SimilarityEuclidean DistanceMatrix TransposeMatrix TraceManhattan Distance

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

Accepts: array

You must run your code first.