用python写一段运算两个数点乘和叉乘的运算
时间: 2024-05-05 13:16:39 浏览: 82
pytorch点乘与叉乘示例讲解
5星 · 资源好评率100%
点乘运算:
```python
a = [1, 2, 3]
b = [4, 5, 6]
dot_product = sum([a[i]*b[i] for i in range(len(a))])
print("Dot product: ", dot_product)
```
输出:
```
Dot product: 32
```
叉乘运算:
```python
a = [1, 2, 3]
b = [4, 5, 6]
cross_product = [a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0]]
print("Cross product: ", cross_product)
```
输出:
```
Cross product: [-3, 6, -3]
```
阅读全文