Welcome to the SciPy courseware for ITSE-1372 Int Comp Program Python at Austin Community College in Austin, TX.
The college website for this course is: https://www.austincode.com/baldwin/ .
This course does not use a conventional paper or electronic textbook. Instead, this online study guide and the Blackboard learning management system will guide you through a variety of free online resources on topics that you will need to learn in order to succeed in the course.
You probably learned about functions when you enrolled in your first programming course. In particular, you learned that if the same block of code appears two or more times within a program, it can often be useful to encapsulate that block of code in a function. After that, you can simply call the function each time you need to execute that block of code, thus reducing redundancy and reducing the likelihood of programming errors that result from typing redundant copies of the same code at various points within the program.
Sometime after that, you probably learned that blocks of code or procedures that are often used in two or more different programs can be placed in function libraries. The library can be made accessible to the program being written using procedures that depend on the language being used to write the program. After that, whenever the main program needs to execute that procedure, it can simply call the appropriate function in the library to cause the procedure to be executed.
This process can be continued upward resulting in higher and higher levels of abstraction. At some point as the function libraries become more abstract, the programmer doesn't even need to care how the function actually implements the procedure so long is the function is trusted and it meets the requirements of the procedure.
The SciPy library is a very high level function library that concentrates on abstracting away the details of very complicated mathematical processes. For example, in the resource titled Solving a system of linear equations, you will learn that in order to use matrix algebra to find the solution for a system of linear equations, you need to invert a square matrix and you also need to multiply the inverted matrix by a column matrix.
Writing the code to invert a matrix is no small task, particularly when the size of the matrix is 4x4 or greater. However, the SciPy library contains a function named inv that will invert the matrix for you and will do so in a way that is probably more efficient than would be the case if you were to write the Python code to do the matrix inversion from scratch. We don't need to be concerned about how the inv function inverts the matrix, we simply trust that it will do so correctly and efficiently.
The SciPy library also provides a function named dot that we can call to perform the required matrix multiplication. Thus, we can create the appropriate matrices to describe the system of equations and then call the inv function and the dot function in the proper order to obtain the solution.
The abstraction doesn't stop there. The SciPy library extends the abstraction to at least one level higher. The library provides a function named solve that accepts the two matrices as parameters and performs the necessary steps to return a matrix containing the solution. Therefore, through the use of the SciPy library, we can solve a system of four linear equations with four unknowns with only three Python statements similar to the following (where the first two statements simply create the matrices).
A = np.array([[1,3,5,7],[2,5,1,3],[2,3,8,1],[1,2,3,4]]) b = np.array([[10],[8],[3],[1]]) stuv = np.linalg.solve(A,b)
Note that in this solution, the requirement to invert the matrix and the requirement to perform the matrix multiplication have been eliminated. The values of the unknowns, s, t, u, and v are returned in an array referenced by the variable named stuv.
To solve systems of 5, 6, 7, 8, or more linear equations, all we need to do is to add the appropriate elements to each of the arrays in the above code to describe the larger more complex problem. Up to some point, we can count on the solve function to return the correct solution regardless of the sizes of the matrices that are passed to the function.
Note however that some systems of equations don't have a unique solution, in which case the solve function will return an error. Such equations are said to be inconsistent.
Inconsistent equations are defined as two or more equations that are impossible to solve based on using one set of values for the variables. An example of a set of inconsistent equations is x+2=4 and x+2=6.
While it isn't necessary for the programmer who uses functions from the SciPy library to know exactly how they are implemented, it is important for the programmer to have a good understanding of the problem that the function is designed to solve. In other words, it is important for the programmer in the above example to understand what is meant by a system of equations and what it means to find a solution for a system of equations. I will have more to say about this later.
According to SciPy.org/SciPy Tutorial,
SciPy is a collection of mathematical algorithms and convenience functions built on the Numpy extension of Python. It adds significant power to the interactive Python session by providing the user with high-level commands and classes for manipulating and visualizing data. With SciPy an interactive Python session becomes a data-processing and system-prototyping environment rivaling systems such as MATLAB, IDL, Octave, R-Lab, and SciLab.
According to SciPy.org/Getting Started,
SciPy and friends can be used for a variety of tasks:
You learned about NumPy in the prerequisite course (ITSE 1302). This is the web page for the competency titled Introduction to the SciPy library. See the other pages in this online study guide for material that deals with the other competencies.
According to SciPy.org/SciPy Tutorial,
SciPy is organized into sub-packages covering different scientific computing domains.
As you can see from the above list, SciPy covers a wide spectrum of scientific computing domains. If you do a quick scan through the SciPy Tutorial, you will probably recognize that an understanding of most of these mathematical domains requires knowledge of mathematics well beyond the prerequisite mathematical knowledge required for enrolling in this course. That is why this competency is titled simply as an Introduction to the SciPy library.
As an introduction, this competency will deal with only two of those domains (linear algebra and Fourier transforms). The intent is to provide examples of SciPy function usage that can probability be understood by students who are enrolled in the course despite their possibly limited background in mathematics. (Students with mathematical capability up through trigonometry should be able to understand the underlying mathematical concepts for those two domains.)
The following is a list of useful online resources in no particular order.
There is no shortage of free online resources for this competency. An Internet search will likely reveal many more.
The following web pages were developed specifically for this course. They provide many examples and exercises designed to help you learn how to use the SciPy library.
You can view a static HTML rendering of the notebook for each of these examples by clicking on the link in the following list. You can view the corresponding notebook file (filename.ipynb) by downloading this zip file, extracting the ipynb file into the file manager area of your Jupyter Notebook installation, and opening the ipynb file in Jupyter Notebook. The name of the ipynb file for each example notebook page is provided in the housekeeping material at the end of the notebook page.
You are encouraged to study these examples and exercises in parallel with your study of the online resources for this competency. All of the homework assignments for this competency will deal with some aspect of linear equations, Fourier analysis, and the SciPy library.
The assessments for this competency consist of several take-home programming assignments in the areas of linear algebra and Fourier transforms plus one proctored test. The assignments will be administered through Blackboard.
Some of the free online resources may also include graded assessments such as exercises and tests. You are encouraged to take advantage of those exercises and tests to enhance your ability to learn and retain the material. However, grades and credits associated with those resources will not be integrated into your grade for this course. Your grade for this course will be based solely on your grades on assignments, projects, and tests administered by your ACC instructor through Blackboard.
Author: Prof. Richard G. Baldwin
Affiliation: Professor of Computer
Information Technology at Austin Community College in Austin, TX.
File:
SciPy.htm
Revised: 09/03/18
Copyright 2018 Richard G.
Baldwin
-end-