当前位置:网站首页>Basic experiment of data statistics and analysis - basic grammar and operation

Basic experiment of data statistics and analysis - basic grammar and operation

2022-06-23 07:27:00 Hebuter-Rui

The experimental requirements

Students are required to be familiar with practical software ( Such as python、Matlab、R etc. ) Basic programming content in , Master the methods of debugging practical software and running programs 、 The idea of task oriented programming , The idea of data statistics and analysis is designed for the task 、 Programming , In particular, master the practical software statements of common machine learning algorithms and various graphics and image rendering methods . We should pay attention to cultivating students' good programming habits , Implement the programming style introduced in the course from beginning to end . In order to ensure that the programming task can be completed within the uniformly arranged computer time , Students should do problem analysis in advance , And conduct static inspection . Students should record the problems encountered in the experiment , And write a detailed experimental report . Prepare the computer program before class , Start the machine and debug carefully , Write an experiment report after class , The experiment report includes the purpose of the experiment 、 Experimental content 、 Source program and experimental results .

The experiment purpose

Master practical software ( Such as python、Matlab、R Wait, choose one ) Basic syntax 、 How to use basic data types , Master inputting and calculating basic types of data from the keyboard , Proficient in branch 、 Loop and other statements control program flow .

Experimental content

1. Programming , Record the information of ten students , At least include the name 、 Age 、 Year of birth 、 Experimental results of data statistical analysis course , Before program output n The average age of a student 、 Average experimental score of data statistical analysis course ,n Is the input parameter of the function .

Source code :

import numpy as np
import xlrd     # read excel
stu_name = []   # Define a list of names 
stu_age = []    # Define age list 
stu_year = []   # Define the birth year list 
stu_score = []  # Define the score list 
data = xlrd.open_workbook('E:\ Learning materials \ Basis of data statistics and analysis \ experiment 1\student.xls')
table = data.sheets()[0]

def get():      # Read from file 10 Student information 
    for i in range(table.nrows):
        stu_name.append(str(table.cell_value(i, 0)))
        stu_age.append(int(table.cell_value(i, 1)))
        stu_year.append(int(table.cell_value(i, 2)))
        stu_score.append(int(table.cell_value(i, 3)))

def avg(n):    # Before calculation n Average score and average age of students 
    avg_age = np.mean(np.array(stu_age)[:n]) 
    avg_score = np.mean(np.array(stu_score)[:n])
    return avg_age, avg_score

def main():
    get()
    n = int(input(" Input n:"))
    print(" The average age is :%.2f" % avg(n)[0])
    print(" The average score is :%.2f" % avg(n)[1])
    
if __name__ == '__main__':
    main()

 2. find 1 to 999 Between 13 The multiple of or the first two digits are 13 The number of , Output these numbers , And count how many .

Source code :

import numpy


def main():
    num = 0
    for i in range(1,1000,1):
        if i%13 == 0 or i//10 == 13:
            num += 1
            print(i)

if __name__ == '__main__':
    main()

3. Write a function that converts grades to grade points , use 98,93,89,73,66 Call the function separately , Generate corresponding grade point .

Source code :

import numpy

def jd(i):
    if i >= 90:
        n = 4.0
    else:
        n = (i-50)/10
    print(" The grade point is :",n)

def main():
    for j in range(5):
        i = int(input(" Please enter the grade :"))
        jd(i)

if __name__ == '__main__':
    main()

4. Randomly generate two with a length of 100 And obey the standard normal distribution vector , Then swap the values of all even bits of the two vectors , Output all 4 Vector ( Before the exchange 2 individual , After the exchange 2 individual ).

Source code :

import numpy as np

def main():
    a = np.random.randn(100)
    b = np.random.randn(100)
    print(a)
    print(b)
    for i in range(1,100,2):
        t = a[i]
        a[i] = b[i]
        b[i] = t
    print(a)
    print(b)

if __name__ == '__main__':
    main()

5、 It is known that XYZ+YZZ=532, among X、Y and Z Is the number , Calculate by programming X,Y and Z Value .

Source code :

import numpy

def main():
    for x in range(6):
        for y in range(6):
            for z in range(10):
                if 100*x+10*y+z+100*y+10*z+z == 532:
                    print("x=",x,"\ty=",y,"\tz=",z)

if __name__ == '__main__':
    main()

原网站

版权声明
本文为[Hebuter-Rui]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230605430699.html