Skip to content

Instantly share code, notes, and snippets.

#read in the image
img = plt.imread('penguin.jpg')
#convert image to grayscale
greyImg = np.mean(img, axis=2).astype(np.uint8)
#the edge kernel, when convolved with our image, detects the edges
edge_kernel = np.array([[0,1,0],[1,-4,1],[0,1,0]])
#convolve edge kernel with image
#define the ticker symbol
tickerSymbol = 'MSFT'
#get data on this ticker
tickerData = yf.Ticker(tickerSymbol)
#get recommendation data for ticker
tickerData.recommendations
#define the ticker symbol
tickerSymbol = 'MSFT'
#get data on this ticker
tickerData = yf.Ticker(tickerSymbol)
#get event data for ticker
tickerData.calendar
#define the ticker symbol
tickerSymbol = 'MSFT'
#get data on this ticker
tickerData = yf.Ticker(tickerSymbol)
#info on the company
tickerData.info
import yfinance as yf
#define the ticker symbol
tickerSymbol = 'MSFT'
#get data on this ticker
tickerData = yf.Ticker(tickerSymbol)
#get the historical prices for this ticker
tickerDf = tickerData.history(period='1d', start='2010-1-1', end='2020-1-25')
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#define the vertical filter
vertical_filter = [[-1,-2,-1], [0,0,0], [1,2,1]]
#define the horizontal filter
horizontal_filter = [[-1,0,1], [-2,0,2], [-1,0,1]]
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
#define the vertical filter
vertical_filter = [[-1,-2,-1], [0,0,0], [1,2,1]]
#define the horizontal filter
horizontal_filter = [[-1,0,1], [-2,0,2], [-1,0,1]]
#set the intensity of the halo
intensity = 250.0
#create a noramlizing constant so the halo fully fades out at the corners
denominator = intensity/((n/2)**2 + (m/2)**2)
#get the normalized squared distances of each pixel from the center
squared_distances = ((x-center_x)**2 + (y-center_y)**2)*denominator
#reshape this 2D matrix into a 3D matrix
#operate on a copy
copyImg = img.copy()
#rotating an image 90 degrees CCW is like mapping the pixel at (x,y) to the pixel at (y,-x)
copyImg = img[y,-x]
#show image
plt.imshow(copyImg)
#get the dimensions of the image
n,m,d = img.shape
#create an open grid for our image
x,y = np.ogrid[0:n, 0:m]