From 76faafc9f39fa3aa428638e254f7218a3a4022d5 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Tue, 2 Apr 2019 21:03:30 -0400 Subject: [PATCH 1/7] add meta-data to IDES and Notebooks --- .../Getting_Started_With_IDEs_and_Notebooks.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md b/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md index 00c04386..7653bee5 100644 --- a/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md +++ b/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Introducing integrated development environments (IDEs) for Python + :keywords: python, introduction, IDE, PyCharm, VSCode +``` + # Setting Up a Development Environment ## What You Will Learn From 8ce847b67bf4f28d0da240af647a47779f747d72 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Tue, 2 Apr 2019 21:54:08 -0400 Subject: [PATCH 2/7] add some metadata tags --- .../GettingStartedWithPython.md | 8 +++++++- .../Getting_Started_With_IDEs_and_Notebooks.md | 4 ++-- .../Informal_Intro_Python.md | 6 ++++++ .../Module1_GettingStartedWithPython/Installing_Python.md | 6 ++++++ .../Module1_GettingStartedWithPython/Jupyter_Notebooks.md | 6 ++++++ Python/Module1_GettingStartedWithPython/SiteFormatting.md | 6 ++++++ .../Problems/DifferenceFanout.md | 7 +++++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Python/Module1_GettingStartedWithPython/GettingStartedWithPython.md b/Python/Module1_GettingStartedWithPython/GettingStartedWithPython.md index d81c720a..001a98c8 100644 --- a/Python/Module1_GettingStartedWithPython/GettingStartedWithPython.md +++ b/Python/Module1_GettingStartedWithPython/GettingStartedWithPython.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Basic description of the Python programming language, Difficulty: Easy, Category: Background + :keywords: python, install, basics, scripts, interpreter, foundations +``` + # Introducing the Python Programming Language @@ -22,7 +28,7 @@ In this section we will learn - How one writes and executes Python code. ## What is Python? -**Python is a programming language**. That is, it provides us with a strict set of grammatical rules that correspond to well-defined instructions that a computer will obey. The tremendous value of this is that we can write text documents that are relatively simple and inuitive for humans to read, and yet can inform the computer to perform precise operations. Python **code** is simply text that conforms to the Python language. +**Python is a programming language**. That is, it provides us with a strict set of grammatical rules that correspond to well-defined instructions that a computer will obey. The tremendous value of this is that we can write text documents that are relatively simple and intuitive for humans to read, and yet can inform the computer to perform precise operations. Python **code** is simply text that conforms to the Python language. For example, the following text obeys the rules of the Python language: diff --git a/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md b/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md index 7653bee5..c1ada19f 100644 --- a/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md +++ b/Python/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.md @@ -14,8 +14,8 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: - :description: Introducing integrated development environments (IDEs) for Python - :keywords: python, introduction, IDE, PyCharm, VSCode + :description: Topic: Integrated Development Environments, Difficulty: Easy, Category: Tools + :keywords: python, introduction, IDE, PyCharm, VSCode, Jupyter, recommendation, tools ``` # Setting Up a Development Environment diff --git a/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md b/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md index a139fbd3..40790b7e 100644 --- a/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md +++ b/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: + :keywords: python, installation, script, introduction +``` + # An Informal Introduction to Python Now that you have the Anaconda distribution of Python installed on your machine, let's write some simple Python code! We are going to forego writing a full Python script for now, and instead make use of a convenient tool for doing quick code scratchwork. The IPython console was installed as a part of Anaconda; it will allow us to build incrementally off of snippets of code, instead of having to execute an entire script all at once. diff --git a/Python/Module1_GettingStartedWithPython/Installing_Python.md b/Python/Module1_GettingStartedWithPython/Installing_Python.md index a81187bc..b0a9d1a5 100644 --- a/Python/Module1_GettingStartedWithPython/Installing_Python.md +++ b/Python/Module1_GettingStartedWithPython/Installing_Python.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Installing Python with Anaconda, Difficulty: Easy, Category: Tutorial + :keywords: python, anaconda, instructions, environments +``` + ## Installing Python Without further adieu, we now provide instructions for installing Python and other useful Python libraries on your machine via the Anaconda platform. Installing the Anaconda platform will install the following: diff --git a/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md b/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md index 91c0e493..512f0de4 100644 --- a/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md +++ b/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Jupyter notebooks, Difficulty: Easy, Category: Tutorial + :keywords: jupyter, notebook, kernel, basics, server, console, command line, plot +``` + # Jupyter Notebooks In recent years, the Jupyter Notebook has become a massively popular tool for doing research-oriented work in Python and other languages alike. Its emergence marked a paradigm shift in the way data science is conducted. diff --git a/Python/Module1_GettingStartedWithPython/SiteFormatting.md b/Python/Module1_GettingStartedWithPython/SiteFormatting.md index 4617a7ab..f5f71a49 100644 --- a/Python/Module1_GettingStartedWithPython/SiteFormatting.md +++ b/Python/Module1_GettingStartedWithPython/SiteFormatting.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Overview of formatting in Python Like You Mean It, Difficulty: Easy, Category: Instructions + :keywords: overview, formatting, background, code block, console style +``` + # A Quick Guide to Formatting This section provides a brief overview of the code formatting style that will be used throughout this text. You are not expected to understand the details of the code, here. This merely provides a guide for what is to come. diff --git a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md index edc2eb34..2d3d5283 100644 --- a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md +++ b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md @@ -12,6 +12,13 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Exercise, Difficulty: Medium, Category: Practice Problem + :keywords: python, for loops, list, function, list comprehension, practice problem +``` + + # Difference Fanout From 342bbc70b64f0d61dac4aab93a3e7e43f0fa2bf4 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Thu, 4 Apr 2019 20:41:18 -0400 Subject: [PATCH 3/7] add meta data for practice problems --- .../Module2_EssentialsOfPython/Problems/DifferenceFanout.md | 2 +- .../Module2_EssentialsOfPython/Problems/EncodeAsString.md | 6 ++++++ .../Module2_EssentialsOfPython/Problems/MarginPercentage.md | 6 ++++++ Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md | 6 ++++++ Python/Module2_EssentialsOfPython/Problems/Palindrome.md | 6 ++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md index 2d3d5283..2d1fd6dc 100644 --- a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md +++ b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md @@ -14,7 +14,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: - :description: Topic: Exercise, Difficulty: Medium, Category: Practice Problem + :description: Topic: For-Loop Exercise, Difficulty: Easy, Category: Practice Problem :keywords: python, for loops, list, function, list comprehension, practice problem ``` diff --git a/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md b/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md index 138779c4..dc06e8a5 100644 --- a/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md +++ b/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: String Encoding Exercise, Difficulty: Medium, Category: Practice Problem + :keywords: python, function, string, casting, practice problem +``` + # Encode as String Sometimes it is very important to handle different input object types differently in a function. This problem will exercise your understanding of types, control-flow, dictionaries, and more. diff --git a/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md b/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md index 17dc9238..3ae6fcf0 100644 --- a/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md +++ b/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Within Margin Exercise, Difficulty: Medium, Category: Practice Problem + :keywords: python, function, control flow, comparisons, practice problem +``` + # Within Margin Percentage diff --git a/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md b/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md index 030b8231..8d89e4b0 100644 --- a/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md +++ b/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Dictionary Merge Exercise, Difficulty: Easy, Category: Practice Problem + :keywords: python, dictionary, merge, practice problem +``` + # Merging Two Dictionaries > Merge two [dictionaries](https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.html#Data-Structures-(Part-II):-Dictionaries) together such that the resulting dictionary always retain the *greater* value among mappings with common keys. diff --git a/Python/Module2_EssentialsOfPython/Problems/Palindrome.md b/Python/Module2_EssentialsOfPython/Problems/Palindrome.md index 852ac228..3113d7b6 100644 --- a/Python/Module2_EssentialsOfPython/Problems/Palindrome.md +++ b/Python/Module2_EssentialsOfPython/Problems/Palindrome.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Palindrome Exercise, Difficulty: Easy, Category: Practice Problem + :keywords: python, string, palindrome, practice problem +``` + # Is Palindrome > A palindrome is a string that reads the same from left to right and from right to left. Strings like `racecar` and `Live on time, emit no evil` are palindromes. Notice that only valid alphanumeric characters are accounted for and that palindromes are not case-sensitive. Given a string, return whether or not it is a palindrome. From 403dc561e39197a2d4de5cea1d1d66c2e3fbce74 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Thu, 4 Apr 2019 21:42:25 -0400 Subject: [PATCH 4/7] metadata --- .../Informal_Intro_Python.md | 4 +- .../Installing_Python.md | 2 +- .../Jupyter_Notebooks.md | 2 +- .../Basic_Objects.md | 6 + .../ConditionalStatements.md | 7 + .../DataStructures.md | 6 + .../DataStructures_III_Sets_and_More.md | 7 + .../DataStructures_II_Dictionaries.md | 6 + Python/Module2_EssentialsOfPython/ForLoops.md | 6 + .../Module2_EssentialsOfPython/Functions.md | 6 + .../Generators_and_Comprehensions.md | 6 + .../Introduction.md | 6 + .../Module2_EssentialsOfPython/Iterables.md | 6 + .../Module2_EssentialsOfPython/Itertools.md | 6 + .../Problems/DifferenceFanout.md | 2 +- .../Problems/EncodeAsString.md | 2 +- .../Problems/MarginPercentage.md | 2 +- .../Problems/MergeMaxDicts.md | 2 +- .../Problems/Palindrome.md | 2 +- Python/Module2_EssentialsOfPython/Scope.md | 6 + .../SequenceTypes.md | 6 + .../Variables_and_Assignment.md | 6 + .../AccessingDataAlongMultipleDimensions.md | 6 + .../AdvancedIndexing.md | 6 + .../ArrayTraversal.md | 6 + .../BasicArrayAttributes.md | 6 + .../Module3_IntroducingNumpy/BasicIndexing.md | 6 + .../Module3_IntroducingNumpy/Broadcasting.md | 6 + .../FunctionsForCreatingNumpyArrays.md | 6 + .../IntroducingTheNDarray.md | 6 + .../Problems/Approximating_pi.ipynb | 1546 +---------------- .../Problems/ComputeAccuracy.md | 6 + .../VectorizedOperations.md | 6 + 33 files changed, 157 insertions(+), 1553 deletions(-) diff --git a/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md b/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md index 40790b7e..aa53eea6 100644 --- a/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md +++ b/Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md @@ -14,8 +14,8 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: - :description: - :keywords: python, installation, script, introduction + :description: Topic: Informal Introduction to Python, Difficulty: Easy, Category: Tutorial + :keywords: python, installation, script, introduction, ipython, console, quick introduction ``` # An Informal Introduction to Python diff --git a/Python/Module1_GettingStartedWithPython/Installing_Python.md b/Python/Module1_GettingStartedWithPython/Installing_Python.md index b0a9d1a5..a932c0a6 100644 --- a/Python/Module1_GettingStartedWithPython/Installing_Python.md +++ b/Python/Module1_GettingStartedWithPython/Installing_Python.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: Installing Python with Anaconda, Difficulty: Easy, Category: Tutorial - :keywords: python, anaconda, instructions, environments + :keywords: python, anaconda, instructions, environments, beginner, data science, introduction ``` ## Installing Python diff --git a/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md b/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md index 512f0de4..9b63e963 100644 --- a/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md +++ b/Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: Jupyter notebooks, Difficulty: Easy, Category: Tutorial - :keywords: jupyter, notebook, kernel, basics, server, console, command line, plot + :keywords: jupyter, notebook, kernel, basics, server, console, command line, plot, beginner, data science ``` # Jupyter Notebooks diff --git a/Python/Module2_EssentialsOfPython/Basic_Objects.md b/Python/Module2_EssentialsOfPython/Basic_Objects.md index b9a8ecbb..486a2850 100644 --- a/Python/Module2_EssentialsOfPython/Basic_Objects.md +++ b/Python/Module2_EssentialsOfPython/Basic_Objects.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Basics of Python Objects, Difficulty: Easy, Category: Section + :keywords: integers, booleans, floats, floating point precision, lists, strings, fundamentals +``` + # Basic Object Types diff --git a/Python/Module2_EssentialsOfPython/ConditionalStatements.md b/Python/Module2_EssentialsOfPython/ConditionalStatements.md index d2c1fd4e..95af737f 100644 --- a/Python/Module2_EssentialsOfPython/ConditionalStatements.md +++ b/Python/Module2_EssentialsOfPython/ConditionalStatements.md @@ -12,6 +12,13 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Conditional Statements, Difficulty: Easy, Category: Section + :keywords: if, else, elif, inline if, switch statement, comparison operator, bool, truth, is operator +``` + + # Conditional Statements
diff --git a/Python/Module2_EssentialsOfPython/DataStructures.md b/Python/Module2_EssentialsOfPython/DataStructures.md index 45b3f3c8..f7889e76 100644 --- a/Python/Module2_EssentialsOfPython/DataStructures.md +++ b/Python/Module2_EssentialsOfPython/DataStructures.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Data Structures, Difficulty: Medium, Category: Section + :keywords: Big-O, complexity, efficiency, algorithm, interview preparation, list, tuple, sequence +``` + # Data Structures (Part I): Introduction Here we survey Python's built-in data structures. You should already be familiar with its lists and tuples, two data structures that facilitate working with sequential data. Two other critical, built-in data structures to be introduced are: diff --git a/Python/Module2_EssentialsOfPython/DataStructures_III_Sets_and_More.md b/Python/Module2_EssentialsOfPython/DataStructures_III_Sets_and_More.md index f8deafb2..5cc59ade 100644 --- a/Python/Module2_EssentialsOfPython/DataStructures_III_Sets_and_More.md +++ b/Python/Module2_EssentialsOfPython/DataStructures_III_Sets_and_More.md @@ -12,6 +12,13 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Introduction to Sets, Difficulty: Medium, Category: Section + :keywords: set, complexity, comparison, union, intersection, membership, hashing, lookup, interview preparation +``` + + # Data Structures (Part III): Sets & the Collections Module ## The "Set" Data Structure The `set` type describes an *unordered* collection of *unique* objects. It is useful for: diff --git a/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md b/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md index 3512c60a..5333500b 100644 --- a/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md +++ b/Python/Module2_EssentialsOfPython/DataStructures_II_Dictionaries.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Introduction to Dictionaries, Difficulty: Medium, Category: Section + :keywords: dictionary, complexity, key, value, iteration, get item, hashing, lookup, interview preparation +``` + # Data Structures (Part II): Dictionaries Python's dictionary allows you to store key-value pairs, and then pass the dictionary a key to quickly retrieve its corresponding value. Specifically, you construct the dictionary by specifying one-way mappings from key-objects to value-objects. **Each key must map to exactly one value**, meaning that a key must be unique. diff --git a/Python/Module2_EssentialsOfPython/ForLoops.md b/Python/Module2_EssentialsOfPython/ForLoops.md index b8f18652..4b37e619 100644 --- a/Python/Module2_EssentialsOfPython/ForLoops.md +++ b/Python/Module2_EssentialsOfPython/ForLoops.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Contorl flow with for-loops and while-loops, Difficulty: Easy, Category: Section + :keywords: for-loop, while-loop, break, control flow, basic programming +``` + # For-Loops and While-Loops In this section, we will introduce the essential "for-loop" control flow paradigm along with the formal definition of an "iterable". The utility of these items cannot be understated. Moving forward, you will likely find use for these concepts in nearly every piece of Python code that you write! diff --git a/Python/Module2_EssentialsOfPython/Functions.md b/Python/Module2_EssentialsOfPython/Functions.md index bfdccfe7..a2d8c6c5 100644 --- a/Python/Module2_EssentialsOfPython/Functions.md +++ b/Python/Module2_EssentialsOfPython/Functions.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Functions and Function Signatures, Difficulty: Medium, Category: Section + :keywords: functions, *args, **kwargs, signature, default parameter, docstring, return, vowel count, syntax, basics +``` + # Basics of Functions
diff --git a/Python/Module2_EssentialsOfPython/Generators_and_Comprehensions.md b/Python/Module2_EssentialsOfPython/Generators_and_Comprehensions.md index f47c1ba1..dc4caa4d 100644 --- a/Python/Module2_EssentialsOfPython/Generators_and_Comprehensions.md +++ b/Python/Module2_EssentialsOfPython/Generators_and_Comprehensions.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: generators comprehensions and efficiency, Difficulty: Easy, Category: Section + :keywords: generator, range, list comprehension, generator comprehension, nested comprehensions, inline for-loop, filtered, iterator +``` + # Generators & Comprehension Expressions
diff --git a/Python/Module2_EssentialsOfPython/Introduction.md b/Python/Module2_EssentialsOfPython/Introduction.md index a5ce57a7..6bbf1be7 100644 --- a/Python/Module2_EssentialsOfPython/Introduction.md +++ b/Python/Module2_EssentialsOfPython/Introduction.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: introduction to control flow, Difficulty: Easy, Category: Section + :keywords: overview, summary, if, else, function, for-loop, if, else, control flow +``` + # Introducing Control Flow Very simply put, to "control flow" in your code is to affect the order in which the diff --git a/Python/Module2_EssentialsOfPython/Iterables.md b/Python/Module2_EssentialsOfPython/Iterables.md index 7635b794..5eb7fc49 100644 --- a/Python/Module2_EssentialsOfPython/Iterables.md +++ b/Python/Module2_EssentialsOfPython/Iterables.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: the basics of iterables in python, Difficulty: Medium, Category: Section + :keywords: iterables, max, min, sum, all, any, itertools, enumerate, unpack +``` + # Iterables Our encounter with for-loops introduced the term *iterable* - an object that can be "iterated over", such as in a for-loop. diff --git a/Python/Module2_EssentialsOfPython/Itertools.md b/Python/Module2_EssentialsOfPython/Itertools.md index 5dbaf858..3b6ec9eb 100644 --- a/Python/Module2_EssentialsOfPython/Itertools.md +++ b/Python/Module2_EssentialsOfPython/Itertools.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: simple use cases of python itertools, Difficulty: Easy, Category: Tutorial + :keywords: itertools, examples, zip, range, enumerate, chain, combinations +``` + # Python's "Itertools" Python has an [itertools module](https://docs.python.org/3/library/itertools.html), which provides a core set of fast, memory-efficient tools for creating iterators. We will briefly showcase a few itertools here. The majority of these functions create [generators](https://www.pythonlikeyoumeanit.com/Module2_EssentialsOfPython/Generators_and_Comprehensions.html), thus we will have to iterate over them in order to explicitly demonstrate their use. It is hard to overstate the utility of this module - it is strongly recommended that you take some time to see what it has in store. diff --git a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md index 2d1fd6dc..e56ab94e 100644 --- a/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md +++ b/Python/Module2_EssentialsOfPython/Problems/DifferenceFanout.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: For-Loop Exercise, Difficulty: Easy, Category: Practice Problem - :keywords: python, for loops, list, function, list comprehension, practice problem + :keywords: for loops, list, function, list comprehension, practice problem ``` diff --git a/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md b/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md index dc06e8a5..19af2c47 100644 --- a/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md +++ b/Python/Module2_EssentialsOfPython/Problems/EncodeAsString.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: String Encoding Exercise, Difficulty: Medium, Category: Practice Problem - :keywords: python, function, string, casting, practice problem + :keywords: function, string, casting, practice problem ``` # Encode as String diff --git a/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md b/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md index 3ae6fcf0..d8b24c81 100644 --- a/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md +++ b/Python/Module2_EssentialsOfPython/Problems/MarginPercentage.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: Within Margin Exercise, Difficulty: Medium, Category: Practice Problem - :keywords: python, function, control flow, comparisons, practice problem + :keywords: function, control flow, comparisons, practice problem ``` diff --git a/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md b/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md index 8d89e4b0..43ebbbbc 100644 --- a/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md +++ b/Python/Module2_EssentialsOfPython/Problems/MergeMaxDicts.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: Dictionary Merge Exercise, Difficulty: Easy, Category: Practice Problem - :keywords: python, dictionary, merge, practice problem + :keywords: dictionary, merge, practice problem ``` diff --git a/Python/Module2_EssentialsOfPython/Problems/Palindrome.md b/Python/Module2_EssentialsOfPython/Problems/Palindrome.md index 3113d7b6..4921dcbe 100644 --- a/Python/Module2_EssentialsOfPython/Problems/Palindrome.md +++ b/Python/Module2_EssentialsOfPython/Problems/Palindrome.md @@ -15,7 +15,7 @@ jupyter: ```raw_mimetype="text/restructuredtext" .. meta:: :description: Topic: Palindrome Exercise, Difficulty: Easy, Category: Practice Problem - :keywords: python, string, palindrome, practice problem + :keywords: string, palindrome, practice problem ``` diff --git a/Python/Module2_EssentialsOfPython/Scope.md b/Python/Module2_EssentialsOfPython/Scope.md index 667709b1..b784bdd4 100644 --- a/Python/Module2_EssentialsOfPython/Scope.md +++ b/Python/Module2_EssentialsOfPython/Scope.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: variable score and namespaces in python, Difficulty: Medium, Category: Section + :keywords: variable, namespace, function, scope, shadowing +``` + # Scope diff --git a/Python/Module2_EssentialsOfPython/SequenceTypes.md b/Python/Module2_EssentialsOfPython/SequenceTypes.md index da9c4e6d..25790196 100644 --- a/Python/Module2_EssentialsOfPython/SequenceTypes.md +++ b/Python/Module2_EssentialsOfPython/SequenceTypes.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: understanding python sequences, Difficulty: Easy, Category: Section + :keywords: list, tuple, string, slice, index, negative index, get item, pop, append, examples +``` + # Sequence Types diff --git a/Python/Module2_EssentialsOfPython/Variables_and_Assignment.md b/Python/Module2_EssentialsOfPython/Variables_and_Assignment.md index 4865b3de..9e317466 100644 --- a/Python/Module2_EssentialsOfPython/Variables_and_Assignment.md +++ b/Python/Module2_EssentialsOfPython/Variables_and_Assignment.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: variable naming and assignment, Difficulty: Medium, Category: Section + :keywords: variable naming, valid names, mutable, immutable, reference, pointer +``` + # Variables & Assignment
diff --git a/Python/Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.md b/Python/Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.md index 2e4d750d..85f78fe4 100644 --- a/Python/Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.md +++ b/Python/Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Indexing into multi-dimensional numpy arrays, Difficulty: Easy, Category: Section + :keywords: numpy array, multidimensional, index, slice, negative index, rows, columns +``` + # Accessing Data Along Multiple Dimensions in an Array In this section, we will: diff --git a/Python/Module3_IntroducingNumpy/AdvancedIndexing.md b/Python/Module3_IntroducingNumpy/AdvancedIndexing.md index 1e29000a..ee7a0530 100644 --- a/Python/Module3_IntroducingNumpy/AdvancedIndexing.md +++ b/Python/Module3_IntroducingNumpy/AdvancedIndexing.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Advanced indexing with numpy arrays, Difficulty: Hard, Category: Section + :keywords: numpy array, integer array indexing, boolean array indexing, copy indexing, advanced +``` + # Advanced Indexing diff --git a/Python/Module3_IntroducingNumpy/ArrayTraversal.md b/Python/Module3_IntroducingNumpy/ArrayTraversal.md index a0e19a69..115b2f34 100644 --- a/Python/Module3_IntroducingNumpy/ArrayTraversal.md +++ b/Python/Module3_IntroducingNumpy/ArrayTraversal.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Numpy array traversal ordering, Difficulty: Medium, Category: Section + :keywords: row-major order, c order, column-major order, f order, traversal, array iteration +``` + # Iterating Over Arrays & Array-Traversal Order In this section, you will learn: diff --git a/Python/Module3_IntroducingNumpy/BasicArrayAttributes.md b/Python/Module3_IntroducingNumpy/BasicArrayAttributes.md index 50a69205..527ee446 100644 --- a/Python/Module3_IntroducingNumpy/BasicArrayAttributes.md +++ b/Python/Module3_IntroducingNumpy/BasicArrayAttributes.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Numpy array attributes, Difficulty: Easy, Category: Section + :keywords: ndim, shape, size, itemsize, dtype, examples +``` + # Basic Array Attributes Armed with our understanding of multidimensional NumPy arrays, we now look at methods for programmatically inspecting an array's attributes (e.g. its dimensionality). It is especially important to understand what an array's "shape" is. diff --git a/Python/Module3_IntroducingNumpy/BasicIndexing.md b/Python/Module3_IntroducingNumpy/BasicIndexing.md index 18cc3dfe..54c20e14 100644 --- a/Python/Module3_IntroducingNumpy/BasicIndexing.md +++ b/Python/Module3_IntroducingNumpy/BasicIndexing.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Numpy array basic indexing, Difficulty: Medium, Category: Section + :keywords: basic index, slice, no copy index, multidimensional array, nd array, view, reverse, axis +``` + # Introducing Basic and Advanced Indexing diff --git a/Python/Module3_IntroducingNumpy/Broadcasting.md b/Python/Module3_IntroducingNumpy/Broadcasting.md index c1a2bb66..6911821d 100644 --- a/Python/Module3_IntroducingNumpy/Broadcasting.md +++ b/Python/Module3_IntroducingNumpy/Broadcasting.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Numpy array broadcasting, Difficulty: Medium, Category: Section + :keywords: broadcasting, vectorization, rules, mismatched shapes, distances +``` + # Array Broadcasting NumPy provides a mechanism for performing mathematical operations on arrays of *unequal* shapes: diff --git a/Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md b/Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md index 85030ca4..67f18ec4 100644 --- a/Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md +++ b/Python/Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Creating numpy arrays, Difficulty: Easy, Category: Section + :keywords: create array, ndarray, ones, random, zeros, empty, examples, arange, linspace, reshape, hstack, vstack +``` + # Functions for Creating NumPy Arrays This section presents standard methods for creating NumPy arrays of varying shapes and contents. NumPy provides a laundry list of functions for creating arrays: diff --git a/Python/Module3_IntroducingNumpy/IntroducingTheNDarray.md b/Python/Module3_IntroducingNumpy/IntroducingTheNDarray.md index e63e73ba..a5c0ffa8 100644 --- a/Python/Module3_IntroducingNumpy/IntroducingTheNDarray.md +++ b/Python/Module3_IntroducingNumpy/IntroducingTheNDarray.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Introduction to numpy arrays, Difficulty: Easy, Category: Section + :keywords: numpy array, ndarray, introduction, overview +``` + # Introducing the ND-array It is time to start familiarizing ourselves with NumPy, the premiere library for doing numerical work in Python. To use this package, we need to be sure to "import" the NumPy module into our code: diff --git a/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb b/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb index ad788160..32548102 100644 --- a/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb +++ b/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb @@ -305,777 +305,6 @@ "outputs": [ { "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "window.mpl = {};\n", - "\n", - "\n", - "mpl.get_websocket_type = function() {\n", - " if (typeof(WebSocket) !== 'undefined') {\n", - " return WebSocket;\n", - " } else if (typeof(MozWebSocket) !== 'undefined') {\n", - " return MozWebSocket;\n", - " } else {\n", - " alert('Your browser does not have WebSocket support.' +\n", - " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", - " 'Firefox 4 and 5 are also supported but you ' +\n", - " 'have to enable WebSockets in about:config.');\n", - " };\n", - "}\n", - "\n", - "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", - " this.id = figure_id;\n", - "\n", - " this.ws = websocket;\n", - "\n", - " this.supports_binary = (this.ws.binaryType != undefined);\n", - "\n", - " if (!this.supports_binary) {\n", - " var warnings = document.getElementById(\"mpl-warnings\");\n", - " if (warnings) {\n", - " warnings.style.display = 'block';\n", - " warnings.textContent = (\n", - " \"This browser does not support binary websocket messages. \" +\n", - " \"Performance may be slow.\");\n", - " }\n", - " }\n", - "\n", - " this.imageObj = new Image();\n", - "\n", - " this.context = undefined;\n", - " this.message = undefined;\n", - " this.canvas = undefined;\n", - " this.rubberband_canvas = undefined;\n", - " this.rubberband_context = undefined;\n", - " this.format_dropdown = undefined;\n", - "\n", - " this.image_mode = 'full';\n", - "\n", - " this.root = $('
');\n", - " this._root_extra_style(this.root)\n", - " this.root.attr('style', 'display: inline-block');\n", - "\n", - " $(parent_element).append(this.root);\n", - "\n", - " this._init_header(this);\n", - " this._init_canvas(this);\n", - " this._init_toolbar(this);\n", - "\n", - " var fig = this;\n", - "\n", - " this.waiting = false;\n", - "\n", - " this.ws.onopen = function () {\n", - " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", - " fig.send_message(\"send_image_mode\", {});\n", - " if (mpl.ratio != 1) {\n", - " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", - " }\n", - " fig.send_message(\"refresh\", {});\n", - " }\n", - "\n", - " this.imageObj.onload = function() {\n", - " if (fig.image_mode == 'full') {\n", - " // Full images could contain transparency (where diff images\n", - " // almost always do), so we need to clear the canvas so that\n", - " // there is no ghosting.\n", - " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", - " }\n", - " fig.context.drawImage(fig.imageObj, 0, 0);\n", - " };\n", - "\n", - " this.imageObj.onunload = function() {\n", - " fig.ws.close();\n", - " }\n", - "\n", - " this.ws.onmessage = this._make_on_message_function(this);\n", - "\n", - " this.ondownload = ondownload;\n", - "}\n", - "\n", - "mpl.figure.prototype._init_header = function() {\n", - " var titlebar = $(\n", - " '
');\n", - " var titletext = $(\n", - " '
');\n", - " titlebar.append(titletext)\n", - " this.root.append(titlebar);\n", - " this.header = titletext[0];\n", - "}\n", - "\n", - "\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._init_canvas = function() {\n", - " var fig = this;\n", - "\n", - " var canvas_div = $('
');\n", - "\n", - " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", - "\n", - " function canvas_keyboard_event(event) {\n", - " return fig.key_event(event, event['data']);\n", - " }\n", - "\n", - " canvas_div.keydown('key_press', canvas_keyboard_event);\n", - " canvas_div.keyup('key_release', canvas_keyboard_event);\n", - " this.canvas_div = canvas_div\n", - " this._canvas_extra_style(canvas_div)\n", - " this.root.append(canvas_div);\n", - "\n", - " var canvas = $('');\n", - " canvas.addClass('mpl-canvas');\n", - " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", - "\n", - " this.canvas = canvas[0];\n", - " this.context = canvas[0].getContext(\"2d\");\n", - "\n", - " var backingStore = this.context.backingStorePixelRatio ||\n", - "\tthis.context.webkitBackingStorePixelRatio ||\n", - "\tthis.context.mozBackingStorePixelRatio ||\n", - "\tthis.context.msBackingStorePixelRatio ||\n", - "\tthis.context.oBackingStorePixelRatio ||\n", - "\tthis.context.backingStorePixelRatio || 1;\n", - "\n", - " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband = $('');\n", - " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", - "\n", - " var pass_mouse_events = true;\n", - "\n", - " canvas_div.resizable({\n", - " start: function(event, ui) {\n", - " pass_mouse_events = false;\n", - " },\n", - " resize: function(event, ui) {\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " stop: function(event, ui) {\n", - " pass_mouse_events = true;\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " });\n", - "\n", - " function mouse_event_fn(event) {\n", - " if (pass_mouse_events)\n", - " return fig.mouse_event(event, event['data']);\n", - " }\n", - "\n", - " rubberband.mousedown('button_press', mouse_event_fn);\n", - " rubberband.mouseup('button_release', mouse_event_fn);\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " rubberband.mousemove('motion_notify', mouse_event_fn);\n", - "\n", - " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", - " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", - "\n", - " canvas_div.on(\"wheel\", function (event) {\n", - " event = event.originalEvent;\n", - " event['data'] = 'scroll'\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " mouse_event_fn(event);\n", - " });\n", - "\n", - " canvas_div.append(canvas);\n", - " canvas_div.append(rubberband);\n", - "\n", - " this.rubberband = rubberband;\n", - " this.rubberband_canvas = rubberband[0];\n", - " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", - " this.rubberband_context.strokeStyle = \"#000000\";\n", - "\n", - " this._resize_canvas = function(width, height) {\n", - " // Keep the size of the canvas, canvas container, and rubber band\n", - " // canvas in synch.\n", - " canvas_div.css('width', width)\n", - " canvas_div.css('height', height)\n", - "\n", - " canvas.attr('width', width * mpl.ratio);\n", - " canvas.attr('height', height * mpl.ratio);\n", - " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", - "\n", - " rubberband.attr('width', width);\n", - " rubberband.attr('height', height);\n", - " }\n", - "\n", - " // Set the figure to an initial 600x600px, this will subsequently be updated\n", - " // upon first draw.\n", - " this._resize_canvas(600, 600);\n", - "\n", - " // Disable right mouse context menu.\n", - " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", - " return false;\n", - " });\n", - "\n", - " function set_focus () {\n", - " canvas.focus();\n", - " canvas_div.focus();\n", - " }\n", - "\n", - " window.setTimeout(set_focus, 100);\n", - "}\n", - "\n", - "mpl.figure.prototype._init_toolbar = function() {\n", - " var fig = this;\n", - "\n", - " var nav_element = $('
')\n", - " nav_element.attr('style', 'width: 100%');\n", - " this.root.append(nav_element);\n", - "\n", - " // Define a callback function for later on.\n", - " function toolbar_event(event) {\n", - " return fig.toolbar_button_onclick(event['data']);\n", - " }\n", - " function toolbar_mouse_event(event) {\n", - " return fig.toolbar_button_onmouseover(event['data']);\n", - " }\n", - "\n", - " for(var toolbar_ind in mpl.toolbar_items) {\n", - " var name = mpl.toolbar_items[toolbar_ind][0];\n", - " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", - " var image = mpl.toolbar_items[toolbar_ind][2];\n", - " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", - "\n", - " if (!name) {\n", - " // put a spacer in here.\n", - " continue;\n", - " }\n", - " var button = $('');\n", - " button.click(method_name, toolbar_event);\n", - " button.mouseover(tooltip, toolbar_mouse_event);\n", - " nav_element.append(button);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = $('');\n", - " nav_element.append(status_bar);\n", - " this.message = status_bar[0];\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = $('
');\n", - " var button = $('');\n", - " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", - " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", - " buttongrp.append(button);\n", - " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", - " titlebar.prepend(buttongrp);\n", - "}\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(el){\n", - " var fig = this\n", - " el.on(\"remove\", function(){\n", - "\tfig.close_ws(fig, {});\n", - " });\n", - "}\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(el){\n", - " // this is important to make the div 'focusable\n", - " el.attr('tabindex', 0)\n", - " // reach out to IPython and tell the keyboard manager to turn it's self\n", - " // off when our div gets focus\n", - "\n", - " // location in version 3\n", - " if (IPython.notebook.keyboard_manager) {\n", - " IPython.notebook.keyboard_manager.register_events(el);\n", - " }\n", - " else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._key_event_extra = function(event, name) {\n", - " var manager = IPython.notebook.keyboard_manager;\n", - " if (!manager)\n", - " manager = IPython.keyboard_manager;\n", - "\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which == 13) {\n", - " this.canvas_div.blur();\n", - " event.shiftKey = false;\n", - " // Send a \"J\" for go to next cell\n", - " event.which = 74;\n", - " event.keyCode = 74;\n", - " manager.command_mode();\n", - " manager.handle_keydown(event);\n", - " }\n", - "}\n", - "\n", - "mpl.figure.prototype.handle_save = function(fig, msg) {\n", - " fig.ondownload(fig, null);\n", - "}\n", - "\n", - "\n", - "mpl.find_output_cell = function(html_output) {\n", - " // Return the cell and output element which can be found *uniquely* in the notebook.\n", - " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", - " // IPython event is triggered only after the cells have been serialised, which for\n", - " // our purposes (turning an active figure into a static one), is too late.\n", - " var cells = IPython.notebook.get_cells();\n", - " var ncells = cells.length;\n", - " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", - " data = data.data;\n", - " }\n", - " if (data['text/html'] == html_output) {\n", - " return [cell, data, j];\n", - " }\n", - " }\n", - " }\n", - " }\n", - "}\n", - "\n", - "// Register the function which deals with the matplotlib target/channel.\n", - "// The kernel may be null if the page has been refreshed.\n", - "if (IPython.notebook.kernel != null) {\n", - " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", - "}\n" - ], "text/plain": [ "" ] @@ -1977,7 +435,7 @@ ] }, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ diff --git a/Python/Module3_IntroducingNumpy/Problems/ComputeAccuracy.md b/Python/Module3_IntroducingNumpy/Problems/ComputeAccuracy.md index 64c27a23..a4e7323d 100644 --- a/Python/Module3_IntroducingNumpy/Problems/ComputeAccuracy.md +++ b/Python/Module3_IntroducingNumpy/Problems/ComputeAccuracy.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Measuring classification accuracy, Difficulty: Easy, Category: Practice Problem + :keywords: numpy, vectorization, practice, machine learning, classifier +``` + # Measuring the Accuracy of a Classification Model Suppose that we are working on a project in which we have some model that can process an image and classify its content. For example, my `cat_dog_goose_other` function tries to classify whether a picture is of a cat (class 0), a dog (class 1), a goose (class 2), or something else (class 3). We want to measure the *accuracy* of our classifier. That is, we want to feed it a series of images whose contents are known and tally the number of times the model's prediction matches the true content of an image. The accuracy is the fraction of images that the model classifies correctly. diff --git a/Python/Module3_IntroducingNumpy/VectorizedOperations.md b/Python/Module3_IntroducingNumpy/VectorizedOperations.md index 611483a9..c9f9c6cb 100644 --- a/Python/Module3_IntroducingNumpy/VectorizedOperations.md +++ b/Python/Module3_IntroducingNumpy/VectorizedOperations.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Vectorized operations with numpy arrays, Difficulty: Easy, Category: Section + :keywords: vectorize, optimized, calculation, numpy, fast, C routine, MKL, sum, linear algebra, optimized +``` + # "Vectorized" Operations: Optimized Computations on NumPy Arrays From 3ade20bcc92679baa0245535a4decc9d96f0397b Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Thu, 4 Apr 2019 22:05:04 -0400 Subject: [PATCH 5/7] add remaining metadata --- Python/Module4_OOP/Applications_of_OOP.md | 6 ++++++ Python/Module4_OOP/Brief_Review.md | 6 ++++++ Python/Module4_OOP/ClassDefinition.md | 7 +++++++ Python/Module4_OOP/ClassInstances.md | 6 ++++++ Python/Module4_OOP/Inheritance.md | 6 ++++++ Python/Module4_OOP/Introduction_to_OOP.md | 6 ++++++ Python/Module4_OOP/Methods.md | 6 ++++++ Python/Module4_OOP/Special_Methods.md | 6 ++++++ Python/Module5_OddsAndEnds/Modules_and_Packages.md | 6 ++++++ Python/Module5_OddsAndEnds/WorkingWithFiles.md | 6 ++++++ Python/Module5_OddsAndEnds/Writing_Good_Code.md | 10 +++++++++- 11 files changed, 70 insertions(+), 1 deletion(-) diff --git a/Python/Module4_OOP/Applications_of_OOP.md b/Python/Module4_OOP/Applications_of_OOP.md index 4134be46..31f9bc21 100644 --- a/Python/Module4_OOP/Applications_of_OOP.md +++ b/Python/Module4_OOP/Applications_of_OOP.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Applications of object-oriented programming, Difficulty: Medium, Category: Section + :keywords: summary, tutorial, python shopping list, object oriented, method, attribute +``` + # Applications of Object Oriented Programming We have spent a considerable amount of time learning about the syntax and definitions of classes, class objects, instances, and methods. Let's take a moment to gather our knowledge and create a useful class. This will help develop a sense for the ways in which object oriented programming can be useful for us. We will try to take care to make some recommendations when one should and shouldn't define their own classes. diff --git a/Python/Module4_OOP/Brief_Review.md b/Python/Module4_OOP/Brief_Review.md index b9c8ae72..94b3b9f1 100644 --- a/Python/Module4_OOP/Brief_Review.md +++ b/Python/Module4_OOP/Brief_Review.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Brief review of object oriented programming, Difficulty: Easy, Category: Tutorial + :keywords: class definition, simple, examples, overview, init, initialize, type, object +``` + ## A Brief Summary of Terms and Concepts diff --git a/Python/Module4_OOP/ClassDefinition.md b/Python/Module4_OOP/ClassDefinition.md index 812cb7bd..77bb461c 100644 --- a/Python/Module4_OOP/ClassDefinition.md +++ b/Python/Module4_OOP/ClassDefinition.md @@ -12,6 +12,13 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: The rules for defining classes in python, Difficulty: Easy, Category: Section + :keywords: class definition, scope, class object, attribute, method +``` + + # Defining a New Class of Object diff --git a/Python/Module4_OOP/ClassInstances.md b/Python/Module4_OOP/ClassInstances.md index a6eaa03c..a7cfbe96 100644 --- a/Python/Module4_OOP/ClassInstances.md +++ b/Python/Module4_OOP/ClassInstances.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Class instances versus objects, Difficulty: Medium, Category: Section + :keywords: instance, class creation, init, self, isinstance +``` + # Instances of a Class diff --git a/Python/Module4_OOP/Inheritance.md b/Python/Module4_OOP/Inheritance.md index d264f191..95eda792 100644 --- a/Python/Module4_OOP/Inheritance.md +++ b/Python/Module4_OOP/Inheritance.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Class inheritance, Difficulty: Easy, Category: Section + :keywords: inherit, object oriented, overwrite, sub class, issubclass +``` + # Inheritance A final topic for us to discuss in this introduction to object oriented programming is the concept of inheritance. Working with inheritance provides powerful abstractions and elegant code re-use - it permits a class to inherit and build off of the attributes of another class. diff --git a/Python/Module4_OOP/Introduction_to_OOP.md b/Python/Module4_OOP/Introduction_to_OOP.md index a359eebf..bc34fafa 100644 --- a/Python/Module4_OOP/Introduction_to_OOP.md +++ b/Python/Module4_OOP/Introduction_to_OOP.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Introducing object oriented programming in python, Difficulty: Easy, Category: Section + :keywords: class, type, creation, definition, intro, overview, basics, meaning +``` + # Introduction to Object Oriented Programming diff --git a/Python/Module4_OOP/Methods.md b/Python/Module4_OOP/Methods.md index 9a80ce89..79d9bf10 100644 --- a/Python/Module4_OOP/Methods.md +++ b/Python/Module4_OOP/Methods.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: The different kinds of class methods, Difficulty: Medium, Category: Section + :keywords: instance, class method, static method, property, abstract method, class funtion +``` + # Methods diff --git a/Python/Module4_OOP/Special_Methods.md b/Python/Module4_OOP/Special_Methods.md index 9bc930e8..c1e9c780 100644 --- a/Python/Module4_OOP/Special_Methods.md +++ b/Python/Module4_OOP/Special_Methods.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Controlling behavior with special methods, Difficulty: Medium, Category: Section + :keywords: dunder method, special method, operator overload, repr, getitem, custom syntax, __init__ +``` + # Special Methods In this section, we will learn about a variety of instance methods that are reserved by Python, which affect an object's high level behavior and its interactions with operators. These are known as special methods. `__init__` is an example of a special method; recall that it controls the process of creating instances of a class. Similarly, we will see that `__add__` controls the behavior of an object when it is operated on by the `+` symbol, for example. In general, the names of special methods take the form of `____`, where the two underscores preceed and succeed the name. Accordingly, special methods can also be referred to as "dunder" (double-underscore) methods. Learning to leverage special methods will enable us to design elegant and powerful classes of objects. diff --git a/Python/Module5_OddsAndEnds/Modules_and_Packages.md b/Python/Module5_OddsAndEnds/Modules_and_Packages.md index 658a84d3..40a39915 100644 --- a/Python/Module5_OddsAndEnds/Modules_and_Packages.md +++ b/Python/Module5_OddsAndEnds/Modules_and_Packages.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Understanding imports modules and packages, Difficulty: Easy, Category: Section + :keywords: custom package, module, script, import, setup, pip, conda, relative import, absolute import +``` + # Import: Modules and Packages diff --git a/Python/Module5_OddsAndEnds/WorkingWithFiles.md b/Python/Module5_OddsAndEnds/WorkingWithFiles.md index c8d72d3d..887d5090 100644 --- a/Python/Module5_OddsAndEnds/WorkingWithFiles.md +++ b/Python/Module5_OddsAndEnds/WorkingWithFiles.md @@ -12,6 +12,12 @@ jupyter: name: python3 --- +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Working with aths and files, Difficulty: Medium, Category: Section + :keywords: open file, read file, pathlib, join directory, context manager, close file, rb, binary file, utf-8, encoding, pickle, numpy, load, archive, npy, npz, pkl, glob, read lines, write, save +``` + # Working with Files This section will discuss the best practices for writing Python code that involves reading from and writing to files. We will learn about the built-in `pathlib.Path` object, which will help to ensure that the code that we write is portable across operating systems (OS) (e.g. Windows, MacOS, Linux). We will also be introduced to a *context manager*, `open`, which will permit us to read-from and write-to a file safely; by "safely" we mean that we will be assured that any file that we open will eventually be closed properly, so that it will not be corrupted even in the event that our code hits an error. Next, we will learn how to "glob" for files, meaning that we will learn to search for and list files whose names match specific patterns. Lastly, we will briefly encounter the `pickle` module which allows us to save (or "pickle") and load Python objects to and from your computer's file system. diff --git a/Python/Module5_OddsAndEnds/Writing_Good_Code.md b/Python/Module5_OddsAndEnds/Writing_Good_Code.md index beed8277..e157ff38 100644 --- a/Python/Module5_OddsAndEnds/Writing_Good_Code.md +++ b/Python/Module5_OddsAndEnds/Writing_Good_Code.md @@ -12,6 +12,14 @@ jupyter: name: python3 --- + +```raw_mimetype="text/restructuredtext" +.. meta:: + :description: Topic: Writing good code, Difficulty: Easy, Category: Section + :keywords: pep8, code style, lint, format, best practices, type hint, documentation, numpydoc, sphinx, typing, annotation, whitespace +``` + + # Writing Good Code Throughout PLYMI we have been concerned with learning the rules for writing valid Python code. That is, we have taken care to ensure that our computers can understand the instructions that we have written for them. Here, we will discuss methods for making our code easier for *humans* to understand. Specifically, we will study: @@ -489,7 +497,7 @@ The following is a summary some of the most critical members of the `typing` mod - Hint a dictionary that maps any hashable to booleans: `Dict[Hashable, bool]`| -#### `Callable[[], ...], ` +#### `Callable[[], `] - **What it hints:** A callable (e.g. a function or a method) that takes in arguments of specified types and returns the specified type - **Examples:** From 5267c258221499d169838ca899e39b3d0cd7e3fd Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Thu, 4 Apr 2019 22:09:12 -0400 Subject: [PATCH 6/7] add tags --- Python/Module5_OddsAndEnds/Matplotlib.ipynb | 16 +++++++++++++++- Python/Module5_OddsAndEnds/Writing_Good_Code.md | 1 - 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Python/Module5_OddsAndEnds/Matplotlib.ipynb b/Python/Module5_OddsAndEnds/Matplotlib.ipynb index 06e598f4..0b180989 100644 --- a/Python/Module5_OddsAndEnds/Matplotlib.ipynb +++ b/Python/Module5_OddsAndEnds/Matplotlib.ipynb @@ -1,5 +1,18 @@ { "cells": [ + { + "cell_type": "raw", + "metadata": { + "raw_mimetype": "text/restructuredtext" + }, + "source": [ + "```raw_mimetype=\"text/restructuredtext\"\n", + ".. meta::\n", + " :description: Topic: Plotting with matplotlib, Difficulty: Easy, Category: Section\n", + " :keywords: plot, matplotlib, figure, axes, functional, object oriented, histogram, image, save, load, color, colormap, API, style, notebook, inline\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -6911,6 +6924,7 @@ } ], "metadata": { + "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3", "language": "python", @@ -6926,7 +6940,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.7.2" } }, "nbformat": 4, diff --git a/Python/Module5_OddsAndEnds/Writing_Good_Code.md b/Python/Module5_OddsAndEnds/Writing_Good_Code.md index e157ff38..8ca1e354 100644 --- a/Python/Module5_OddsAndEnds/Writing_Good_Code.md +++ b/Python/Module5_OddsAndEnds/Writing_Good_Code.md @@ -19,7 +19,6 @@ jupyter: :keywords: pep8, code style, lint, format, best practices, type hint, documentation, numpydoc, sphinx, typing, annotation, whitespace ``` - # Writing Good Code Throughout PLYMI we have been concerned with learning the rules for writing valid Python code. That is, we have taken care to ensure that our computers can understand the instructions that we have written for them. Here, we will discuss methods for making our code easier for *humans* to understand. Specifically, we will study: From 64af4467d651e83b56b9c99f5ea31a7e23814ef4 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Thu, 4 Apr 2019 22:23:01 -0400 Subject: [PATCH 7/7] fix bad notebooks --- .../Problems/Approximating_pi.ipynb | 1546 ++++++++++++++++- Python/Module5_OddsAndEnds/Matplotlib.ipynb | 4 +- 2 files changed, 1545 insertions(+), 5 deletions(-) diff --git a/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb b/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb index 32548102..ad788160 100644 --- a/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb +++ b/Python/Module3_IntroducingNumpy/Problems/Approximating_pi.ipynb @@ -305,6 +305,777 @@ "outputs": [ { "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " if (mpl.ratio != 1) {\n", + " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", + " }\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " fig.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var backingStore = this.context.backingStorePixelRatio ||\n", + "\tthis.context.webkitBackingStorePixelRatio ||\n", + "\tthis.context.mozBackingStorePixelRatio ||\n", + "\tthis.context.msBackingStorePixelRatio ||\n", + "\tthis.context.oBackingStorePixelRatio ||\n", + "\tthis.context.backingStorePixelRatio || 1;\n", + "\n", + " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width * mpl.ratio);\n", + " canvas.attr('height', height * mpl.ratio);\n", + " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], "text/plain": [ "" ] @@ -435,7 +1977,7 @@ ] }, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ diff --git a/Python/Module5_OddsAndEnds/Matplotlib.ipynb b/Python/Module5_OddsAndEnds/Matplotlib.ipynb index 0b180989..0f12a77b 100644 --- a/Python/Module5_OddsAndEnds/Matplotlib.ipynb +++ b/Python/Module5_OddsAndEnds/Matplotlib.ipynb @@ -6,11 +6,9 @@ "raw_mimetype": "text/restructuredtext" }, "source": [ - "```raw_mimetype=\"text/restructuredtext\"\n", ".. meta::\n", " :description: Topic: Plotting with matplotlib, Difficulty: Easy, Category: Section\n", - " :keywords: plot, matplotlib, figure, axes, functional, object oriented, histogram, image, save, load, color, colormap, API, style, notebook, inline\n", - "```" + " :keywords: plot, matplotlib, figure, axes, functional, object oriented, histogram, image, save, load, color, colormap, API, style, notebook, inline\n" ] }, {