“скалярное произведение” Ответ

точечный продукт Ocaml

let rec safe_dot_product (vect1: int list) (vect2: int list) : int option = 
  match (vect1, vect2) with
    | [],[] -> Some 0
    | [],_ -> None
    | _,[] -> None
    | (x::xs, y::ys) ->
      match safe_dot_product xs ys with
        | None -> None
        | Some m -> Some ((x*y) + m)
JunJun

точечный продукт Python

A = [1,2,3,4,5,6]
B = [2,2,2,2,2,2]

# with numpy
import numpy as np
np.dot(A,B) # 42
np.sum(np.multiply(A,B)) # 42
#Python 3.5 has an explicit operator @ for the dot product
np.array(A)@np.array(B)# 42
# without numpy
sum([A[i]*B[i] for i in range(len(B))]) # 42
Bored Coder

скалярное произведение

Let a be the direction vector <a1, a2, a3>
Let b be the direction vector <b1, b2, b3>

Dot Product (final answer is a scalar):
a • b = <a1, a2, a3> • <b1, b2, b3> = (a1)(b1) + (a2)(b2) + (a3)(b3) or
a • b = ||a||||b||cosθ, where θ is the angle between the two vectors,
						||a|| is the magnitude of a, and
                        ||b|| is the magnitude of b

If a • b = 0, the angle between the two vectors is π rad (90°)
			  meaning the two vectors are orthogonal (perpendicular).

If vector "dot-products" with itself:
a • a = ||a||^2, where ||a|| is the length of a.
Saf1

Numpy Dot Product

a = np.array([[1,2],[3,4]]) 
b = np.array([[11,12],[13,14]]) 
np.dot(a,b)
[[37  40], [85  92]] 
Old-fashioned Okapi

r Dot Product

a = c(1,2)
b = c(0,1)

# Perform the dot product
a%*%b
Trustworthy Whale

скалярное произведение

import numpy as np

# input: [[1,2,3,...], [4,5,6,...], ...]
def dot_product(vector, print_time= True):
    if print_time:
        print("----Dot Product----")
    dot_product = []
    for j in range(len(vector[0])):
        col = []
        for i in range(len(vector)):
            col.append(vector[i][j])
        prod_col = np.prod(col)
        dot_product.append(prod_col)
    sum_dot_product = np.sum(dot_product)
    
    if print_time:
        print(f"input vector: {vector}, => dot product = {sum_dot_product}")
        print("================================")
    return sum_dot_product
  
vector1 = [1,2,3]
vector2 = [4,5,6]
vector3 = [2,4,3]
vector4 = [2,4,3]
vector = [vector1, vector2, vector3, vector4]
  
dot_product(vector)
# or
dot_product([vector2, vector4])
# or
# the False parameter, disables the printing in the function.
print(dot_product(vector,False))
SMR

Ответы похожие на “скалярное произведение”

Вопросы похожие на “скалярное произведение”

Больше похожих ответов на “скалярное произведение” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования