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
import numpy as np
lst=[[1,3,5],[2,4,6]]
print(type(lst))
np_lst=np.array(lst)
print(type(np_lst))
np_lst=np.array(lst,dtype=np.float)
print(np_lst.shape)
print(np_lst.ndim)
print(np_lst.dtype)
print(np_lst.itemsize)
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
import numpy as np
print(np.zeros([2,4]))
print(np.ones([3,5]))
print("Rand:")
print(np.random.rand(2,4))
print(np.random.rand())
print("RandInt:")
print(np.random.randint(1,10))
print(np.random.randint(1,10,3))
#标准正态随机数
print("Randn:")
print(np.random.randn(2,4))
print("Choice:")
print(np.random.choice([10,20,30,2,8]))
print("Distribute:")
print(np.random.beta(1,10,100))
2. Running results
[[0.0.0.0.]
[0.0.0.0.]]
[[1.1.1.1.1.]
[1.1.1.1.1.]
[1.1.1.1.1.]]
Rand:
[[0.902201410.53545960.90832360.96268421]
[0.835276060.034453280.569252350.75789267]]
0.8128122424230132
RandInt:
4
[725]
Randn:
[[0.68700498-0.27635927-0.50090856-0.24558428]
[1.060551580.074170260.928740251.73472707]]
Choice:
20
Distribute:
[0.105204770.058352280.150815480.068825090.059831220.05248901
0.017116910.065622140.068027130.088252510.178780870.02111876
0.09691770.043373150.031732620.075367340.016598390.05821397
0.161156750.002636980.50100860.004224150.030147020.17149838
0.017918740.035264370.082306410.017776270.088855380.05613144
0.074784890.02873450.024234820.047815830.080665580.24980657
0.016834870.127688470.125125260.032443590.125556230.05167776
0.055691650.024578280.102738310.062891360.025742610.23747873
0.050321580.04884150.180323960.091808520.006061930.00378815
0.151545950.064324170.461332260.222463780.029000070.03095598
0.247842440.179159350.023313780.018997010.203750490.08266777
0.023091420.083259980.119411450.053434460.13488790.14747583
0.117551080.141027070.070442890.003816290.057899830.0654181
0.100489660.006342720.46237450.004164650.100583170.00988711
0.274182160.065760760.033061310.078905460.084925330.01243208
0.056024980.114475260.049329550.018098950.129734140.23358211
0.295033660.112927210.012101160.02871565]