Chapter summary - Unit 5
Packages:
How to build a GUI Program: Create a GUI that handles an event, more skills for working
with components;
Numpy Basics: Arrays and Vectorized Computation: Creating ndarrays, Data Types for
ndarrays, Operations between Arrays and Scalars, Basic Indexing and Slicing, Indexing with
slices, Boolean Indexing, Transposing Arrays and Swapping Axes;
Getting started with Pandas: Introduction to Pandas Data Structures, Summarizing and
Computing Descriptive Statistics, Handling missing data;
Plotting and Visualization: A Brief matplotlib API Primer, Plotting Functions in panda
GUI with Tkinter
Tkinter is a package in python that aids graphical applications. Installation of Tkinter can be done by
| |
Creating a window
Mainloop aids the program in running recursively. This can be further improved by naming each part of the root window.
- Widgets: Widgets are the graphical objects that are found in tkinter. This inclues the root window all the labels and the entry field etc. The widgets should be mapped to other objects in order to work which can be a canvas or the root window as a base window.
Some example of widgets
- Label: displays text or image on the screen
- Button: adds a clickable button to the application
- Entry: allows single line text input from user
- Text: allows multi-line text input and formatting
- Frame: holds and organizes other widgets
- Scale: provides a graphical slider to select a value
- Listbox: displays a list of items to choose from
- Checkbutton: displays a toggle button with two states (on/off)
- Radiobutton: displays a button that can be selected from a group of buttons
Calling function in tkinter
An application made in Tkinter
| |
Numpy
The numpy library is a python library that can be used to manupulate and work on complex numberical applications. NumPy supports numpy array which is ideal to perform large array operations since the faster access time. The NumPy library also supports broadcasting which is performing an operation throughout the array without using a for loop.
N dimentional array (Nd Array)
- Why is NumPy faster than lists
- NumPy arrays are stored at one continuous place in memory unlike lists, so processes can access and manipulate them very efficiently.
- This behavior is called locality of reference in computer science.
- This is the main reason why NumPy is faster than lists. Also it is optimized to work with latest CPU architectures.
- Operating on the elements in a list can only be done through iterative loops, which is computationally inefficient in Python.
- The NumPy package enables users to overcome the shortcomings of the Python lists by providing the data storage object called ndarray
- The ndarray is similar to lists, but rather than being highly flexible by storing different types of objects in one list, only the same type of element can be stored in each column.
- For example, with a Python list, you could make the first element a list and the second another list or dictionary. With NumPy arrays, you can only store the same type of element, e.g., all elements must be floats, integers, or strings.
- Despite this limitation, ndarray wins hands down when it comes to operation times, as the operations are sped up significantly.
- Creating ND array
| |
- Slicing the ND array
The slicing works in a similar fashion as compared to for loops (except the step). You can nest string slicing to reduce the dimentions of the nDarray.