Assignment 3
Due: 3:00 PM on Wednesday, February 13, 2008
Question #1
Consider the following file format for storing a real-valued 3D-matrix:
The first line gives the dimensions of the x, y, and z-axes of
this matrix, respectively, and the subsequent lines in the file can be
broken into x blocks describing the 2D-planes of the matrix associated with
x-values 1 through numX, where each block in turn consists of numY lines,
each describing a vector of numZ z-values for associated with each y-value
1 through numY.
Write and document a Python script slice2D.py which takes as
command-line arguments an input 3D-matrix file, an output 2D-matrix file,
an axis-slice specification, and a number-format, and writes the specified
2D-slice of the 3D-matrix to the specified output file. An axis-slice
specification is a string, where the first character specifies
the axis ("x", "y", or "z") and the remaining characters are a number
between 1 and the dimension of that axis that specifies the slice. A
numerical format is any string specifying a numerical format recognized
by the Python string-formatting facility, e.g., 5.1e, 10.3f, 4d.
An x-axis slice is written out as numY lines of numZ values apiece,
a y-axis slice is written out as numX lines of numZ values apiece, and
a z-axis slice is written out as numX lines of numY values apiece.
This script must produce the appropriate error message (see typescript-file
below) when either the axis-specification or specified axis-slice are
incorrect. Your script must work on datafile
slice2D1.dat
to produce the output given in typescript-file
slice2D.script. You may assume that all given
datafiles are formatted correctly and are readable, and that all given
numeric-format strings are correct.
Question #2
Consider the tagged input file described in Assignment #2. The score
associated with a referee's evaluation of a paper is the sum of all
5 scores given by that referee divided by 5 and multiplied by a confidence
factor, which is 1/3, 2/3, and 1 when the confidence-ratings are L(ow),
M(edium), and H(igh), respectively. The score associated with a paper
is the average of the evaluation-scores of all referees assigned to that
paper. Write and document a Python script paporder.py which takes as
command-line arguments a tagged input file of the format described
above, and prints a list (sorted from highest average score to lowest)
of the papers in that file, displaying for each paper its average score,
the author(s), and the title.
Your script must work on datafile
paporder1.dat
to produce the output given in typescript-file
paporder.script.
You may assume that all given
tagged files are formatted correctly and are readable, and that all
referees in each tagged file have supplied all scores.
Hints
You may find nested lists, as well as
the behavior of the various sort-commands in Python on nested
lists, of use.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
At the top of each script, please include a triple-quoted docstring
with your name and student number, the name of this course and the
assignment number, and a brief description of your program; also include
brief comments throughout your program describing various code-blocks.
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems (which use Python Version 2.4) as part of the
assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- Feb 5, 12:25pm
Output script-files for Assignment #3 posted.
- Feb 1, 2:40pm
Assignment #3 posted; output script-files to be posted soon.
Created: February 1, 2008
Last Modified: February 5, 2008