Introduction to numpy

a numpy

1. Keywords: open source, data computing extension
2. Functions: ndarray, multidimensional operations, linear algebra
3. Official website: http://www.numpy.org
4. Installation method: pip install numpy 
two code
  1. import numpy as np
  2. lst=[[1,3,5],[2,4,6]]
  3. print(type(lst))
  4. np_lst=np.array(lst)
  5. print(type(np_lst))
  6. np_lst=np.array(lst,dtype=np.float)
  7. print(np_lst.shape)
  8. print(np_lst.ndim)
  9. print(np_lst.dtype)
  10. print(np_lst.itemsize)
  11. print(np_lst.size)
Three running results
<class 'list'>
<class 'numpy.ndarray'>
(2, 3)
2
float64
8
6
Four numpy commonly used Array
1. Code
  1. import numpy as np
  2. print(np.zeros([2,4]))
  3. print(np.ones([3,5]))
  4. print("Rand:")
  5. print(np.random.rand(2,4))
  6. print(np.random.rand())
  7. print("RandInt:")
  8. print(np.random.randint(1,10))
  9. print(np.random.randint(1,10,3))
  10. #标准正态随机数
  11. print("Randn:")
  12. print(np.random.randn(2,4))
  13. print("Choice:")
  14. print(np.random.choice([10,20,30,2,8]))
  15. print("Distribute:")
  16. print(np.random.beta(1,10,100))
2. Running results
  1. [[0.0.0.0.]
  2. [0.0.0.0.]]
  3. [[1.1.1.1.1.]
  4. [1.1.1.1.1.]
  5. [1.1.1.1.1.]]
  6. Rand:
  7. [[0.902201410.53545960.90832360.96268421]
  8. [0.835276060.034453280.569252350.75789267]]
  9. 0.8128122424230132
  10. RandInt:
  11. 4
  12. [725]
  13. Randn:
  14. [[0.68700498-0.27635927-0.50090856-0.24558428]
  15. [1.060551580.074170260.928740251.73472707]]
  16. Choice:
  17. 20
  18. Distribute:
  19. [0.105204770.058352280.150815480.068825090.059831220.05248901
  20. 0.017116910.065622140.068027130.088252510.178780870.02111876
  21. 0.09691770.043373150.031732620.075367340.016598390.05821397
  22. 0.161156750.002636980.50100860.004224150.030147020.17149838
  23. 0.017918740.035264370.082306410.017776270.088855380.05613144
  24. 0.074784890.02873450.024234820.047815830.080665580.24980657
  25. 0.016834870.127688470.125125260.032443590.125556230.05167776
  26. 0.055691650.024578280.102738310.062891360.025742610.23747873
  27. 0.050321580.04884150.180323960.091808520.006061930.00378815
  28. 0.151545950.064324170.461332260.222463780.029000070.03095598
  29. 0.247842440.179159350.023313780.018997010.203750490.08266777
  30. 0.023091420.083259980.119411450.053434460.13488790.14747583
  31. 0.117551080.141027070.070442890.003816290.057899830.0654181
  32. 0.100489660.006342720.46237450.004164650.100583170.00988711
  33. 0.274182160.065760760.033061310.078905460.084925330.01243208
  34. 0.056024980.114475260.049329550.018098950.129734140.23358211
  35. 0.295033660.112927210.012101160.02871565]
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327081646&siteId=291194637