import numpy as np a = np.array( [20,30,40,50] ) b = np.arange(1,5) print("a is ",a,"\n") print("b is ",b,"\n") # 从加减乘除等基本运算中,可以看到,都是numpy中对应的元素的运算 print("a+b",a+b,"\n") print("a-b",a-b,"\n") print("a*b",a*b,"\n") print("a/b",a/b,"\n") print("a<40",a<40,"\n") print("b**2",b**2,"\n") print("10*np.sin(b)",10*np.sin(b),"\n") # 矩阵运算的方式,python有特殊的表达 print("a矩阵与b矩阵相乘",a.dot(b)) print("a矩阵与b矩阵相乘",a@b)
a is [20 30 40 50]
b is [1 2 3 4]
a+b [21 32 43 54]
a-b [19 28 37 46]
a*b [ 20 60 120 200]
a/b [ 20. 15. 13.33333333 12.5 ]
a<40 [ True True False False]
b**2 [ 1 4 9 16]
10*np.sin(b) [ 8.41470985 9.09297427 1.41120008 -7.56802495]
a矩阵与b矩阵相乘 400
a矩阵与b矩阵相乘 400
从相应的运算来看,四则运算是数据很容易理解的。