This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import urllib.request | |
import zipfile | |
import pandas as pd | |
import networkx as nx | |
import matplotlib.pyplot as plt | |
# 1. Set URL and file paths | |
url = "https://aaronclauset.github.io/hierarchy/terrorists.zip" | |
zip_path = "terrorists.zip" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import matplotlib.pyplot as plt | |
from networkx.algorithms.community import greedy_modularity_communities | |
import matplotlib.cm as cm | |
import numpy as np | |
# Load graph | |
G = nx.les_miserables_graph() | |
# Compute centrality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import pandas as pd | |
import plotly.graph_objects as go | |
def monty_hall_5doors_scenario(): | |
"""Generate a single scenario (car location, player choice, etc.) for 5-door Monty Hall.""" | |
doors = [0,1,2,3,4] | |
prize_door = random.randint(0, 4) | |
initial_choice = random.randint(0, 4) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import pandas as pd | |
import plotly.graph_objects as go | |
def monty_hall_5doors(trials=1000, switch=True): | |
""" | |
Runs the Monty Hall game with 5 doors for multiple trials. | |
Returns a DataFrame with columns: [initial_choice, prize_door, result]. | |
""" | |
data = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import numpy as np | |
import pandas as pd | |
# Monty Hall simulation function | |
def monty_hall_simulation(trials=1000, switch=True): | |
results = [] | |
for _ in range(trials): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import numpy as np | |
# Monty Hall simulation function | |
def monty_hall(switch=True): | |
prize_door = random.randint(0, 2) # Randomly assign the prize behind one of the three doors | |
chosen_door = random.randint(0, 2) # Player's initial choice of door | |
doors = [0, 1, 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
def monty_hall_numpy(trials=100000000, switch=True): | |
""" | |
Fully vectorized Monty Hall simulation using NumPy for maximum performance. | |
Parameters: | |
trials (int): Number of games to simulate. | |
switch (bool): If True, the player switches doors; otherwise, they stay. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# Define the Monty Hall function | |
def monty_hall(switch=True): | |
""" | |
Simulates one round of the Monty Hall game. | |
Parameters: | |
switch (bool): If True, the player switches their choice after the host opens a door. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from moviepy.editor import VideoClip, TextClip | |
from tqdm import tqdm | |
def make_frame(t): | |
# Calculate remaining time in minutes and seconds | |
remaining_time = max(0, int(5*60 - t)) | |
minutes, seconds = divmod(remaining_time, 60) | |
time_str = f"{minutes:01d}:{seconds:02d}" | |
# Create TextClip for the countdown with 4K resolution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
openai.api_key = 'sk-API 키를 입력하세요' | |
def lambda_handler(event, context): | |
if 'm' in event['params']['querystring']: | |
input_message = event['params']['querystring']['m'] | |
else: | |
input_message = "나는 신한투자증권에 입사하려는 개발자야. 클라우드를 공부해야 할 필요가 있을까?" |
NewerOlder