Python学习笔记: 快速产生常态分布(Normal distribution)的学生成绩-源自ChatGPT

本文同步发表于小弟自架网站:微确幸资讯站

以下程式码源自于ChatGPT,主要变数说明如下:
n_students:学生人数
n_exams:考试科目数
mean:考试成绩平均数
std_dev:考试成绩标準差

import pandas as pdimport numpy as np# Set the number of students and the number of examsn_students = 20n_exams = 5# Set the mean and standard deviation for the normal distributionmean = 70std_dev = 10# Generate the random scores using numpyscores = np.random.normal(loc=mean, scale=std_dev, size=(n_students, n_exams))# Create a pandas DataFrame to store the scoresdf = pd.DataFrame(scores)# Set the column namesdf.columns = ['Exam ' + str(i+1) for i in range(n_exams)]# Set the row names as the student IDsdf.index = ['Student ' + str(i+1) for i in range(n_students)]# Print the DataFrameprint(df)

http://img2.58codes.com/2024/20122335L4RNPqTRQi.jpg


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章