Python Reading
Key Ideas
- NumPy is Python library written in C to provide fast numerical methods for scientific computation.
- NumPy enables Python users to use a data structure called an array. You can conceptualize an array as an efficient implementation of a list.
- Today we will learn about 1-D (one dimensional) arrays. However, Python arrays can contain any number of dimensions.
Getting Started
- Install NumPy on your machine:
- Windows: python -m pip install numpy
- Mac: pip3 install --user numpy
In-Class Activity
- One way to gain insight into numeric data is to calculate its mean and standard deviation. More information.
- Sometimes it is useful to sort numeric data into either ascending or descending order. Why?
- Download demo.py and conduct experiments until you fully understand it.
- Can you explain how the sort function works?
- The sort function does not return anything. Why does the shoulder_heights array in the main program change?
- Can you modify the sort function so that it sorts the data into descending order?
- The NumPy module includes a sort function. Can you find the relevant documentation and then use it?
- What are other useful things you might want to do with a 1-D array?
Active Learning
Optional Alternative NumPy Installation for Windows Users
Enter the second instruction in the MS-DOS command prompt, from the same directory where the module was downloaded.
- Download numpy, choosing the version in the next instruction.
- python -m pip install numpy-1.13.3+mkl-cp36-cp36m-win32.whl