关键词 > STAT415/STAT515
STAT 415 and STAT 515 Exam 3
发布时间:2021-12-07
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
STAT 415 and STAT 515 Exam 3
1. (20 points) Write and execute Python code that will do the following.
(a) Create a list named x containing the integers from 1 to 5. Is it mutable? Is it ordered? If it is mutable, add values 10 and 11 to this list so that len(x) is equal to 7.
(b) A dictionary named y containing the following data. Is it mutable? Is it ordered? If it is mutable, removes the key c and returns the corresponding value.
key a, b, c, d, e
value 1, 2, 3, 4, 5
(c) A set named A containing the integers from 1 to 5. Is it mutable? Is it ordered? If it is ordered, please return the second value.
(d) A tuple named B containing the integers from 1 to 5. Is it mutable? Is it ordered? If it is ordered, please return the second value. If it is mutable, please replace the second value with 10.
2. (20 points) Write and execute Python code that will do the following.
(a) Create an array named x that contains values {0, 3, 6, 9, 12, 15, 18, 21, 24}. (b) Split the array x into 3 arrays, each of which has 2, 3 and 4 elements in the orginal order.
(c) Reshape the array x to a square matrix y and then add one more column to the left of y to create the matrix z given below
[[ 1 0 3 6]
[ 1 9 12 15]
[ 1 18 21 24]]
(d) Subtract each column of z by [1 10, 19] to output the following matrix
[[ 0 -1
[ -9 -1
[-18 -1
2 5]
2 5]
2 5]]
3. (15 points) Write and execute Python code that will do the following.
(a) Create an array named x with six rows and five columns that contains the data
[[ 1 2 [ 6 7 [11 12 [16 17 [21 22 [26 27
3
8
13
18
23
28
4 5]
9 10]
14 15]
19 20]
24 25]
29 30]]
The array should have dtype equal to float64.
(b) Create a new array named y that is a copy of the sub-array of x corresponding to the rows indexed by {0, 1, 4} and the last two columns of x.
(c) Calculate the row sums for x and print out the results.
4. (10 points) Write and execute Python code that will do the following.
(a) Create a structured arrary from student’s name, class and height below
name class height
Marge Simpson 6 50
Lisa Simpson 10 59
Lois Griffin 8 47
Linda Belcher 5 48
(b) Print out the name and class for students with height greater than 49.
5. (10 points) Write a Python function named mysum whose arguments correspond to an arbitrary number unnamed of objects. The function should return the sum of all argument numbers. For example, mysum(1, 2, 2) should return the value 5.
6. (5 points) Write a Python program using for loop that will count the number of even and odd numbers from a series of numbers, say, x = (1, 2, 3, 4, 5, 6, 7, 8, 9) and print the following output:
Number of even numbers: 4
Number of odd numbers: 5
7. (5 points) Write a Python program using the while loop to find the smallest integer a so that 1.08a is greater than 10.
8. (5 points) Write a Python function named centerColumn with arguments x and center, where x is a two dimensional array (i.e. matrix) and center is a list containing the centering values for all columns of x. That is, each column in x will be centered by the corresponding value in center. If the number of columns in x is not equal to the length of center, the following error will be returned: 'The length of center should be equal to the number of columns in x'. For example, If you function is defined correctly, the following should be returned:
### input:
y = np.array([[1,2],[3,4]])
centerColumn(y, [2, 3])
### output:
array([[-1, -1],
[ 1, 1]])
### input:
y = np.array([[1,2],[3,4]])
centerColumn(y, [2,3,4])
### output:
'The length of center should be equal to the number of columns in x'