my_square = lambda x: x**2
my_square(4)
my_square(9)
def my_square_fn(x):
'''
This function take an input x and return x^2.
Parameters:
-----------
x: float, integer or any other number
Returns:
--------
out = x**2
Example:
>>> out = my_square_fn(4)
>>> out
16
'''
return x**2
my_square_fn(4)
my_square_fn?
list(range(2, 20, 3))
list(range(5))
print('The square of 100 is', my_square(100))
print('The square of 100 is ' + str(my_square(100)))
len(range(100))
len('Some random string ndsyafsdasdwne')
type('hello')
type(3.1415)
type(10)
type([1, 'a', 3])
import os
os.getenv('HOME')
os.path.exists('pics')
pathout = './data'
if os.path.exists(pathout) == False:
os.mkdir(pathout)
from IPython.display import IFrame
url = "https://ourworldindata.org"
IFrame(url, width="100%", height="600px")
from IPython.display import IFrame
url = "https://ourworldindata.org/grapher/countries-democracies-autocracies-row"
IFrame(url, width="100%", height="600px")
from IPython.display import YouTubeVideo
# Replace 'youtube_video_id' with the actual YouTube video ID
youtube_video_id = 'WSKi8HfcxEk?si=zlRPlhGHPq1cOnte'
# Create a YouTubeVideo object
youtube_video = YouTubeVideo(youtube_video_id, width=800, height=600)
# Display the YouTube video
youtube_video
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
x = [0, 1, 2, 3]
y = [my_square(i) for i in x]
plt.plot(x, y, c='r', marker='o', linestyle=':', label=r'$y=x^2$')
plt.legend()
plt.show()
x = [i/10 for i in range(0, 100)]
y = [i**2 for i in x]
z = [100 - 1/4 * i**2 + i for i in x]
fig, ax = plt.subplots(figsize=(8,5))
ax.plot(x, y, c='r', marker='o', markersize=4, linestyle='-.', label=r'$y=x^2$')
ax.plot(x, z, c='b', marker='D', markersize=4, linestyle='-', label=r'$y=100-\frac{1}{4}x^2 + x$')
ax.set_xlabel(r'$x$', fontsize=18)
ax.set_ylabel(r'Value', fontsize=18)
ax.set_title(r'Some Plots', fontsize=24)
ax.legend(fontsize=18)
plt.savefig('./pics/some-plots.png')
plt.savefig('./pics/some-plots.pdf')
plt.show()
import numpy as np
c = [1, 2]
d = [[1, 2], [3, 4]]
ca = np.array(c)
da = np.array(d)
ca
da
ca**2
da * 3
ca*da
print(ca.shape)
print(da.shape)
print('da=', da)
print('Sum of all elements da.sum()=', da.sum())
print('Sum of all elements in each column da.sum(axis=0)=', da.sum(axis=0))
print('Sum of all elements in each row da.sum(axis=1)=', da.sum(axis=1))
print('dot product is ca.dot(da)=', ca.dot(da))
print(np.ones((3,4)))
print(np.zeros((2,2)))
print(np.eye(2))
print(np.ones_like(ca))
np.random.uniform(-1,1,10)
np.random.normal(10, 1, size=(3,3))
#np.random.seed(123456)
x0 = 0
x = [x0]
[x.append(x[-1] + np.random.normal() ) for i in range(500)]
fig, ax = plt.subplots(figsize=(8,5))
ax.plot(x)
plt.title(r'A simple random walk', fontsize=24)
plt.xlabel(r'Period $t$', fontsize=18)
plt.ylabel(r'$x_t$', fontsize=18)
plt.show()
def cobb_douglas_output(A, K, L, alpha):
output = A * (K ** alpha) * (L ** (1 - alpha))
return output
A = 1.0
K = 1000.0
L = 500.0
alpha = 0.7
output_level = cobb_douglas_output(A, K, L, alpha)
print("Output level:", output_level)
import numpy as np
import matplotlib.pyplot as plt
def cobb_douglas_output(A, K, L, alpha):
output = A * (K ** alpha) * (L ** (1 - alpha))
return output
A = 1.0
L = 1.0
K_values = np.linspace(0, 5, 100)
output_values = cobb_douglas_output(A, K_values, L, 0.5)
plt.figure(figsize=(8, 6))
plt.plot(K_values, output_values, label='Cobb-Douglas Production Function')
plt.xlabel('Capital Input (K)')
plt.ylabel('Output')
plt.title('Cobb-Douglas Production Function')
plt.legend()
plt.grid(True)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
def cobb_douglas_output(A, K, L, alpha):
output = A * (K ** alpha) * (L ** (1 - alpha))
return output
L = 1.0
alpha = 0.5
K_values = np.linspace(0, 5, 100)
A_values = [1, 2, 4, 5]
plt.figure(figsize=(8, 6))
for A in A_values:
output_values = cobb_douglas_output(A, K_values, L, alpha)
plt.plot(K_values, output_values, label=f'A = {A}')
plt.xlabel('Capital Input (K)')
plt.ylabel('Output')
plt.title('Effect of Increasing A on Cobb-Douglas Production Function')
plt.legend()
plt.grid(True)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
def cobb_douglas_output(A, K, L, alpha):
output = A * (K ** alpha) * (L ** (1 - alpha))
return output
K = 1.0
alpha = 0.5
L_values = np.linspace(1, 5, 100)
A_values = [1, 2, 4, 5]
plt.figure(figsize=(8, 6))
for A in A_values:
output_values = cobb_douglas_output(A, K, L_values, alpha)
plt.plot(L_values, output_values, label=f'A = {A}')
plt.xlabel('Labor Input (L)')
plt.ylabel('Output')
plt.title('Effect of Increasing L on Cobb-Douglas Production Function')
plt.legend()
plt.grid(True)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
def cobb_douglas_output(A, K, L, alpha):
output = A * (K ** alpha) * (L ** (1 - alpha))
return output
alpha = 0.5
# Generate an array of K and L values from 0 to 5 with 100 points
K_values = np.linspace(0, 5, 100)
L_values = np.linspace(1, 5, 100)
A_values = [1, 2, 4, 5]
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
for A in A_values:
output_values = cobb_douglas_output(A, K_values, L, alpha)
plt.plot(K_values, output_values, label=f'A = {A}')
plt.xlabel('Capital Input (K)')
plt.ylabel('Output')
plt.title('Effect of Increasing A on Cobb-Douglas Production Function')
plt.legend()
plt.grid(True)
plt.subplot(1, 2, 2)
for A in A_values:
output_values = cobb_douglas_output(A, K, L_values, alpha)
plt.plot(L_values, output_values, label=f'A = {A}')
plt.xlabel('Labor Input (L)')
plt.ylabel('Output')
plt.title('Effect of Increasing L on Cobb-Douglas Production Function')
plt.legend()
plt.grid(True)
plt.savefig('cobb_douglas_combined_plot.png')
plt.savefig('cobb_douglas_combined_plot.jpg')
plt.savefig('cobb_douglas_combined_plot.pdf')
plt.tight_layout()
plt.show()
from IPython.display import IFrame
url = "https://fred.stlouisfed.org/searchresults?st=unemployment+by+city"
IFrame(url, width="100%", height="600px")
from IPython.display import IFrame
url = "https://databank.worldbank.org/source/world-development-indicators#"
IFrame(url, width="100%", height="600px")