Numpy-数组

 1 import numpy as np
 2 
 3 # 可以将python中list列表转换为Numpy数组
 4 l = [1,2,3,4]
 5 
 6 # Numpy数组
 7 ndl = np.array(l) # 输入一部分,可以使用tab不全
 8 print(ndl)
 9 display(ndl)  # 显示
10 #output:
11 [1 2 3 4]
12 array([1, 2, 3, 4])
13 
14 
15 nd2 = np.zeros(shape=(3,4),dtype=np.int16) # shift+tab提示方法的属性,
16 nd2
17 #output:
18 array([[0, 0, 0, 0],
19        [0, 0, 0, 0],
20        [0, 0, 0, 0]], dtype=int16)
21 
22 nd3 = np.ones(shape=(3,4),dtype=np.float32)
23 nd3
24 # output
25 array([[1., 1., 1., 1.],
26        [1., 1., 1., 1.],
27        [1., 1., 1., 1.]], dtype=float32)
28 
29 np.full(shape=(3,4,5),fill_value=3.1415926) # 生成任意指定的数据
30 
31 nd5 = np.random.randint(0,100,size=20) # 从0到100生成随机数字,int,整数
32 nd5
33 
34 nd6 = np.random.rand(3,5) # 生成0-1之间的随机数
35 
36 nd7 = np.random.randn(3,5) # 正泰分布,平均值是0,标准差是1
37 nd8 = np.random.normal(loc=175,scale = 10,size=(3,5)) # 正态分布,平均值是175,标准差是10
38 
39 nd9 = np.arange(1,100,step=10) # 等差数列,,左闭右开
40 nd10 = np.linspace(0,99,100) # 等差数列 , 左闭右闭,,100代表生成等差数列的长度 
View Code

 

posted @ 2021-07-29 00:34  Wind_LPH  阅读(31)  评论(0编辑  收藏  举报