python的数组运算(Numpy库)

数组加法

import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2 = np.array([[10,11,12],[13,14,15],[16,17,18]])
sum = arr1 + arr2
print(sum)

运行结果如图

数组减法

import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2 = np.array([[10,11,12],[13,14,15],[16,17,18]])
sum = arr2 - arr1
print(sum)

运行结果如图

数组乘法

#数组点积
import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2 = np.array([[10,11,12],[13,14,15],[16,17,18]])
sum = arr1 * arr2
print(sum)

运行结果如图

#矩阵乘积
import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2 = np.array([[10,11,12],[13,14,15],[16,17,18]])
sum = np.dot(arr1, arr2)
print(sum)

运行结果如图

#数组乘方
import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
sum = arr1**2
print(sum)

运行结果如图

数组除法

import numpy as np
arr1 = np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2 = np.array([[10,11,12],[13,14,15],[16,17,18]])
sum = arr2 // arr1
print(sum)

运行结果如图

posted @ 2021-10-01 19:57  yamadaharuko  阅读(789)  评论(0编辑  收藏  举报