np.array
list_1 = [1,5,7,9,5,1]
list_1_1 = np.array(list_1)
np.zeros 构建全为0的矩阵
list_1 = np.zeros(10,dtype = float)
print(list_1)
#anwser
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
type of list_1 is <class ‘numpy.ndarray’>
np.ones 构建全为1的矩阵
list_1 = np.ones((3,5),dtype = int)
print(list_1)
# anwser
[[1 1 1 1 1]
[1 1 1 1 1]
[1 1 1 1 1]]
np.full
list_1 = np.full((3,5),3.14,dtype = int)
print(list_1)
#anwser
[[3 3 3 3 3]
[3 3 3 3 3]
[3 3 3 3 3]]
np.linspace
list_1 = np.linspace(0,1,5) # 0到1的5个数
print(list_1)
# anwser
[0. 0.25 0.5 0.75 1. ] #均分
np.random.randint
list_1 = np.random.randint(0,5,(3,3)) #0到5的3*3矩阵的随机数
print(list_1)
# anwser
[[3 2 2]
[4 0 2]
[0 4 1]]
np.random.normal
list_1 = np.random.normal(0,1,(3,3)) #方差为1,均值为0的3*3随机数矩阵
print(list_1)
# anwser
[[ 0.90235626 1.08201144 -0.02242838]
[ 1.65496962 1.87613763 1.09563896]
[ 0.8574219 -1.40170292 -1.8910511 ]]
np.eye
list_1 = np.eye(5) #建立一个5*5的单位矩阵
print(list_1)
#anwser
[[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 1. 0.]
[0. 0. 0. 0. 1.]]