Assignment Operators Create some variables a = 2 b = 1 c = 0 d = 3 Assigns values from right side to left side c = a + b c 3 Add right to the left and assign the result to left (c = a + c) c += a c 5 Subtract right …
Day: May 26, 2021
Arithmetic Basics Create some simulated variables x = 6 y = 9 x plus y x + y 15 x minus y x – y -3 x times y x * y 54 the remainder of x divided by y x % y 6 x divided by y x / y 0.6666666666666666 x divided by …
Applying Functions To List Items Create a list of regiment names regimentNames = [‘Night Riflemen’, ‘Jungle Scouts’, ‘The Dragoons’, ‘Midnight Revengence’, ‘Wily Warriors’] Using A For Loop Create a for loop goes through the list and capitalizes each /* create a variable for the for loop results */ regimentNamesCapitalized_f = [] /* for every item …
Apply Operations Over Items In A List Method 1: map() /* Create a list of casualties from battles */ battleDeaths = [482, 93, 392, 920, 813, 199, 374, 237, 244] /* Create a function that updates all battle deaths by adding 100 */ def updated(x): return x + 100 /* Create a list that applies …
Append Using The Operator Create A List /* Create a list of three names */ names = [‘chris’, ‘nguyen’, ‘jack’] Create A Value To Append To The List /* Create a string list variable containing a name */ to_append = [‘sarah’] Append Value To List /* Create a new list with all the original names …
All Combinations For A List Of Objects Preliminary /* Import combinations with replacements from itertools */ from itertools import combinations_with_replacement Create a list of objects /* Create a list of objects to combine */ list_of_objects = [‘warplanes’, ‘armor’, ‘infantry’] Find all combinations (with replacement) for the list /* Create an empty list object to hold …
Add Padding Around String Create Some Text text = ‘Chapter 1’ Add Padding Around Text /* Add Spaces Of Padding To The Left */ format(text, ‘>20’) ‘ Chapter 1’ /* Add Spaces Of Padding To The Right */ format(text, ‘<20’) ‘Chapter 1 ‘ /* Add Spaces Of Padding On Each Side */ format(text, ‘^20’) ‘ …
k-Fold Cross-Validating Neural Networks If we have smaller data it can be useful to benefit from k-fold cross-validation to maximize our ability to evaluate the neural network’s performance. This is possible in Keras because we can “wrap” any neural network such that it can use the evaluation features available in scikit-learn, including k-fold cross-validation. To …
Visualize Performance History Preliminaries /* Load libraries */ import numpy as np from keras.datasets import imdb from keras.preprocessing.text import Tokenizer from keras import models from keras import layers import matplotlib.pyplot as plt /* Set random seed */ np.random.seed(0) Using TensorFlow backend. Load Movie Review Data /* Set the number of features we want */ number_of_features …
Visualize Neural Network Architecture Preliminaries /* Load libraries */ from keras import models from keras import layers from IPython.display import SVG from keras.utils.vis_utils import model_to_dot from keras.utils import plot_model Using TensorFlow backend. Construct Neural Network Architecture /* Start neural network */ network = models.Sequential() /* Add fully connected layer with a ReLU activation function */ …