四则运算
import numpy
a=numpy.array([[1,2,3,4],[5,6,7,8]])
b=numpy.array([[9,10,11,12],[13,14,15,16]])
c=a+b
d=a-b
e=a*b
f=a/b
print(c)
print(d)
print(e)
print(f)
结果:
统计运算
求和
import numpy
a=numpy.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
a1=a.sum()
a2=a.sum(axis=0)
a3=a.sum(axis=1)
print(a1)
print(a2)
print(a3)
结果:
求平均值
import numpy
a=numpy.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
a1=a.mean()
a2=a.mean(axis=0)
a3=a.mean(axis=1)
print(a1)
print(a2)
print(a3)
结果:
求最值
import numpy
a=numpy.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
a1=a.max()
a2=a.max(axis=0)
a3=a.max(axis=1)
b1=a.min()
b2=a.min(axis=0)
b3=a.min(axis=1)
print(a1)
print(a2)
print(a3)
print(b1)
print(b2)
print(b3)
结果:
|