numpy-train-study1.py 497 B

123456789101112131415161718192021222324
  1. #numpy库简单应用
  2. import numpy as np
  3. import random
  4. #定义矩阵大小
  5. m = 15
  6. mBtemp = []
  7. for x in range(2*m-1):
  8. mBtemp.append(random.randint(1, 10))
  9. mB = np.matrix(np.array(mBtemp[0:m]))
  10. for x in range(1, m):
  11. mB = np.insert(mB, x, values=np.array(mBtemp[-1*x:] + mBtemp[0:m-x]), axis = 0)
  12. vb = []
  13. for x in range(m):
  14. vb.append(random.randint(1, 10))
  15. print("B = \n", mB)
  16. print("vb = ", vb)
  17. #invB = np.linalg.inv(mB)
  18. print("Bx = b, x = ", np.linalg.solve(mB, vb))