Skip to content

Instantly share code, notes, and snippets.

View GeorgeSeif's full-sized avatar

George GeorgeSeif

View GitHub Profile
def boxplot(x_data, y_data, base_color="#539caf", median_color="#297083", x_label="", y_label="", title=""):
_, ax = plt.subplots()
# Draw boxplots, specifying desired style
ax.boxplot(y_data
# patch_artist must be True to control box fill
, patch_artist = True
# Properties of median line
, medianprops = {'color': median_color}
# Properties of box
import numpy as np
# Gets the number of axes (dimensions)
np_array.ndim
# Gets the dimensions of the array
np_array.shape
# The total number of elements of the array
# (product of all elements # in np_array.shape)
import numpy as np
### Create your array by directly loading in the data. You can use a list or a tuple.
### If you want to be super thorough, specify the array type
np_array = np.array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
np_array = np.array([(1.5,2,3), (4,5,6)], dtype=float)
### Sometimes, the contents of the initial array may not be known, but we would like
### to initialise one anyways to use it later. We have a number of functions at out
# In Numpy, arithmetic operators on arrays are always applied elementwise.
# A new array is filled and returned with the result.
# For example, if we create 2 arrays a and b, and subtract b
# from a, we will get something like this. Remember that you
# can NOT do such an operation with arrays of differnt sizes,
# you'll get an error
a = np.array( [20,30,40,50] )
b = np.array( [0, 1, 2, 3] )
c = a - b
# Numpy arrays can be indexed, sliced and iterated over just like Python lists
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a[2] # 2
a[2:5] # [2, 3, 4]
a[-1] # 10
a[:8] # [0, 1, 2, 3, 4, 5, 6, 7]
a[2:] # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# We can do the same things with multi-dimensional arrays! Just use commas to separate
b = [[ 0, 1, 2, 3],
### These are all the Numpy data types at your disposal
np.int64 # Signed 64-bit integer types
np.float32 # Standard double-precision floating point
np.complex # Complex numbers represented by 128 floats
np.bool # Boolean type storing TRUE and FALSE values
np.object # Python object type
np.string # Fixed-length string type
np.unicode # Fixed-length unicode type
import glob
import os
import cv2
### Loop through all jpg files in the current folder
### Resize each one to size 600x600
for image_filename in glob.glob("*.jpg"):
### Read in the image data
img = cv2.imread(image_filename)
import glob
import os
import cv2
import concurrent.futures
def load_and_resize(image_filename):
### Read in the image data
img = cv2.imread(image_filename)
# coding: utf-8
import spacy
### Load spaCy's English NLP model
nlp = spacy.load('en_core_web_lg')
### The text we want to examine
text = "Amazon.com, Inc., doing business as Amazon, is an American electronic commerce and cloud computing company based in Seattle, Washington, that was founded by Jeff Bezos on July 5, 1994. The tech giant is the largest Internet retailer in the world as measured by revenue and market capitalization, and second largest after Alibaba Group in terms of total sales. The amazon.com website started as an online bookstore and later diversified to sell video downloads/streaming, MP3 downloads/streaming, audiobook downloads/streaming, software, video games, electronics, apparel, furniture, food, toys, and jewelry. The company also produces consumer electronics - Kindle e-readers, Fire tablets, Fire TV, and Echo - and is the world's largest provider of cloud infrastructure services (IaaS and PaaS). Amazon also sells certain low-end products under its in-house brand AmazonBasics."
# coding: utf-8
import spacy
### Load spaCy's English NLP model
nlp = spacy.load('en_core_web_lg')
### The text we want to examine
text = "Amazon.com, Inc., doing business as Amazon, is an American electronic commerce and cloud computing company based in Seattle, Washington, that was founded by Jeff Bezos on July 5, 1994. The tech giant is the largest Internet retailer in the world as measured by revenue and market capitalization, and second largest after Alibaba Group in terms of total sales. The amazon.com website started as an online bookstore and later diversified to sell video downloads/streaming, MP3 downloads/streaming, audiobook downloads/streaming, software, video games, electronics, apparel, furniture, food, toys, and jewelry. The company also produces consumer electronics - Kindle e-readers, Fire tablets, Fire TV, and Echo - and is the world's largest provider of cloud infrastructure services (IaaS and PaaS). Amazon also sells certain low-end products under its in-house brand AmazonBasics."