import numpy as np
# 1.基本矩阵操作
# 1)算术运算符:加减乘除
n = np.random.randint(0, 10, size=(4, 5))
print(n)
n1 = n + 10
print(n1)
n2 = np.add(n, 10)
print(n2)
n3 = n/2
print(n3)
# 2)矩阵积np.dot()
n4 = np.random.randint(0, 10, size=(2, 3))
n5 = np.random.randint(0, 10, size=(3, 2))
print("***************矩阵积*******************")
print(n4, n5)
n6 = np.dot(n4, n5)
print(n6)
# 3)广播机制 ndarray广播机制的两条机制
# 规则一:为缺失的维度补1
# 规则二:假定缺失元素用已有值填充
'''例1:a=np.ones((2,3)) b= np.arange(3)求a+b'''
a = np.ones((2, 3))
print("**********广播机制**************")
print(a)
b = np.arange(3)
print(b)
# numpy的广播机制,维度不对应,自动补全
c = a + b
print(c)
'''例2:a = np.arange(3).reshape((3,1)), b= np.arange(3),求a+b'''
a = np.arange(3).reshape((3, 1))
print(a)
b = np.arange(3)
print(b)
c = a + b
print(c)
'''习题:a = np.ones((4,1)),b= np.arange(4),求a+b'''
a = np.ones((4, 1))
print(a)
b = np.arange(4)
print(b)
c = a + b
print(c)