创建两个 numpy 数组,其中 arr 1 中存储学生姓名,arr2 中存储学生数学、语文、英语的
成绩,使用索引输出第二个学生的英语成绩和第四个学生三门课程的平均分。

python创建numpy数组,进行索引
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注
望采纳,谢谢,代码:
import numpy as np studenttype = np.dtype({'names': ['name', 'math', 'chinese','english'], 'formats': ['S32', 'int', 'int', 'int']}) students = np.array([('zhangsan', 21, 78, 79), ('lisi', 19, 90, 79), ('wangwu', 22, 98, 70),('zhaoliu', 50, 100, 70)], dtype=studenttype) print(f"第二个学生的姓名是{students[1]['name']}") print(f"第四个同学的全部成绩平均分是{np.mean((students[3]['math'],students[3]['chinese'],students[3]['english']))}")
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用