import numpy as np
1. 列表赋值:
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
2. 自定义结构化类型
student_type = np.dtype([('name', 'U20'), ('sex', 'U1'), ('age', 'i1'), ('marks', 'f4')])
students = np.array([('张三', '男', 18, 87.6), ('李四', '女', 19, 100), ('王五', '男', 28, 85.5)], dtype=student_type)
3. st_end+步长
x = np.arange(10, 20, 3).reshape(2,2)
4. 均匀散列
x = np.linspace(10,20,5)
5. 对数形式
a = np.logspace(1,10,num = 10, base = 2)
6. 范围创建
myarray=np.arange(20)
网友评论