Docsity

Practice Midterm 1 - Introduction to Scientific Programming | COMP 116, Exams of Computer Science

Toggle sidebar
bg1
Comp 116 Fall 2009 Midterm 1 Page 1 of 3
Name:__________________________ Signed:____________________________________
By signing above you indicate agreement with the UNC Honor Code Pledge, that you have not given or
received unauthorized assistance on this exam.
There are a total of 100 points to do in 75 minutes. I have included a brief list of functions you might
find useful as reminders on the last page. You should not need a calculator but you may use one if you
wish. You may not use your cell phone or computer.
Write your answers in the areas provided. You can use the margins or backs of pages as scratch paper. I
have additional scratch paper if you need it. Showing work may help you get partial credit.
1. [30 points] What is the size of the array resulting from each expression? If the expression would
produce an error then write 'Error' in the blank provided. Otherwise write #rows x #columns as
we did on the practice midterm.
______________ A = np.array( [ [ 1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12] ])
______________ B = A.T
______________ C = np.arange( 1, 2, 3)
______________ D = np.zeros( (1000, 2) )
______________ E = np.zeros( (3, 4) ) * np.array( [ 1, 2, 3, 4])
______________ F = np.zeros( (3, 4) ) / np.array( [ [ 1, 2, 3 ] ] ).T
______________ G = np.eye(3) - 3
______________ H = np.ones ( (3, 4) ) % np.array( [ 1, 2, 3 ] )
______________ I = np.random.random_integers(1, 6, 1000)
______________ J = np.array( [ [ 1, 2, 3 ], 4, 5, 6 ] )
2. [30 points] Assume you are given a N x 2 array of daily high (column 0) and low (column 1)
temperatures for some long period of N days. Write expressions to answer the following
questions from the data.
A) What is N? (that is how many days of data do you have?)
B) What was the minimum high temperature recorded?
C) What was the mean low temperature recorded?
D) What was the mean temperature for each day (defined as (low+high)/2)?
pf3

Partial preview of the text

Download Practice Midterm 1 - Introduction to Scientific Programming | COMP 116 and more Exams Computer Science in PDF only on Docsity!

Name:__________________________ Signed:____________________________________ By signing above you indicate agreement with the UNC Honor Code Pledge, that you have not given or received unauthorized assistance on this exam. There are a total of 100 points to do in 75 minutes. I have included a brief list of functions you might find useful as reminders on the last page. You should not need a calculator but you may use one if you wish. You may not use your cell phone or computer. Write your answers in the areas provided. You can use the margins or backs of pages as scratch paper. I have additional scratch paper if you need it. Showing work may help you get partial credit.

  1. [30 points] What is the size of the array resulting from each expression? If the expression would produce an error then write 'Error' in the blank provided. Otherwise write #rows x #columns as we did on the practice midterm. ______________ A = np.array( [ [ 1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12] ]) ______________ B = A.T ______________ C = np.arange( 1, 2, 3) ______________ D = np.zeros( (1000, 2) ) ______________ E = np.zeros( (3, 4) ) * np.array( [ 1, 2, 3, 4]) ______________ F = np.zeros( (3, 4) ) / np.array( [ [ 1, 2, 3 ] ] ).T ______________ G = np.eye(3) - 3 ______________ H = np.ones ( (3, 4) ) % np.array( [ 1, 2, 3 ] ) ______________ I = np.random.random_integers(1, 6, 1000) ______________ J = np.array( [ [ 1, 2, 3 ], 4, 5, 6 ] )
  2. [30 points] Assume you are given a N x 2 array of daily high (column 0) and low (column 1) temperatures for some long period of N days. Write expressions to answer the following questions from the data. A) What is N? (that is how many days of data do you have?) B) What was the minimum high temperature recorded? C) What was the mean low temperature recorded? D) What was the mean temperature for each day (defined as (low+high)/2)?

E) What was the lowest mean temperature? F) Suppose the instruments malfunctioned on a few days so that no reading was available. These entries in the array have the value NaN (Not a Number). Give an expression that will replace each NaN value with the average of the value for the day before and the day after the failure. (don't worry about edge cases at the beginning and end of the data). Hint: Use np.isnan and np.where.

  1. [10 Points] I could represent polynomials using an array of their coefficients. For example 17 + 2X + 5X^2 + 6X^3 could be represented with the coefficient array [17, 2, 5, 6]. For this problem assume the coefficients for a Nth degree polynomial are in the array C (with N+1 elements). Give an expression to evaluate the polynomial for a given value of X. Hint: You'll find the exponentiation operator ** and np.arange useful for this exercise.
  2. [24 Points] Show the array that results from the following expressions. A) C = np.zeros((3,3)); C[:,:] = 1; C B) C = np.zeros((3,3)); C[1:,:] = 1; C C) C = np.zeros((3,3)); C[::2,2::] = 1; C