Square CoCalc Logo
StoreFeaturesDocsShareSupport Try Sign InSign Up
Views: 4
Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu2004-dev
| Embed | Download | Raw
Kernel: Python 3 (system-wide)
In [2]:
import nltk import numpy as np g = np.meshgrid(np.arange(10)-5, np.arange(10)-5) positions = np.append(g[0].reshape(-1,1),g[1].reshape(-1,1),axis=1) print(g[1]) location = (0,2,1) print(location[0], location[2])
Out[2]:
[[-5 -5 -5 -5 -5 -5 -5 -5 -5 -5] [-4 -4 -4 -4 -4 -4 -4 -4 -4 -4] [-3 -3 -3 -3 -3 -3 -3 -3 -3 -3] [-2 -2 -2 -2 -2 -2 -2 -2 -2 -2] [-1 -1 -1 -1 -1 -1 -1 -1 -1 -1] [ 0 0 0 0 0 0 0 0 0 0] [ 1 1 1 1 1 1 1 1 1 1] [ 2 2 2 2 2 2 2 2 2 2] [ 3 3 3 3 3 3 3 3 3 3] [ 4 4 4 4 4 4 4 4 4 4]] 0 1
In [2]:
# import the necessary libraries import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns # from celluloid import Camera from sklearn.compose import ColumnTransformer from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler # Dance to import our logit model import os import sys module_path = os.path.abspath(os.path.join('.')) sys.path.append(module_path) # from logistic_regression import LogisticRegression
In [2]:
import torch from torch import nn from torchvision import datasets from torchvision.transforms import ToTensor
In [1]:
sunny_to = {"sunny":1/2, "cloudy":1/3,"rainy":1/6} cloudy_to = {"sunny":1/3, "cloudy":1/3,"rainy":1/3} rainy_to = {"sunny":2/3, "cloudy":1/6,"rainy":1/6} state = {"sunny":1, "cloudy":0,"rainy":0} weathers = ["sunny","cloudy","rainy"] for _ in range(10): next_state = {} for weather in weathers: next_state[weather] = (sunny_to[weather] * state["sunny"] + cloudy_to[weather] * state["cloudy"] + rainy_to[weather] * state["rainy"]) state = next_state print(state)
Out[1]:
{'sunny': 0.5, 'cloudy': 0.3333333333333333, 'rainy': 0.16666666666666666} {'sunny': 0.4722222222222222, 'cloudy': 0.3055555555555556, 'rainy': 0.2222222222222222} {'sunny': 0.4861111111111111, 'cloudy': 0.2962962962962963, 'rainy': 0.2175925925925926} {'sunny': 0.4868827160493827, 'cloudy': 0.2970679012345679, 'rainy': 0.21604938271604937} {'sunny': 0.48649691358024694, 'cloudy': 0.2973251028806584, 'rainy': 0.21617798353909465} {'sunny': 0.48647548010973934, 'cloudy': 0.29730366941015085, 'rainy': 0.21622085048010972} {'sunny': 0.4864861968449931, 'cloudy': 0.29729652491998165, 'rainy': 0.21621727823502512} {'sunny': 0.4864867922191738, 'cloudy': 0.29729712029416244, 'rainy': 0.21621608748666357} {'sunny': 0.4864864945320834, 'cloudy': 0.29729731875222265, 'rainy': 0.2162161867156937} {'sunny': 0.48648647799391176, 'cloudy': 0.29729730221405093, 'rainy': 0.21621621979203703}
In [3]:
import numpy as np tm = np.array([[1/2,1/3,2/3], [1/3,1/3,1/6], [1/6,1/3,1/6]]) state = np.array([1,0,0]) for _ in range(10): state = tm@state print(state)
Out[3]:
[0.5 0.33333333 0.16666667] [0.47222222 0.30555556 0.22222222] [0.48611111 0.2962963 0.21759259] [0.48688272 0.2970679 0.21604938] [0.48649691 0.2973251 0.21617798] [0.48647548 0.29730367 0.21622085] [0.4864862 0.29729652 0.21621728] [0.48648679 0.29729712 0.21621609] [0.48648649 0.29729732 0.21621619] [0.48648648 0.2972973 0.21621622]
In [2]:
import sys, pygame pygame.init()
Out[2]:
pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html
In [2]:
import sys, pygame pygame.init() size = width, height = 320, 240 speed = [2, 2] black = 0, 0, 0 screen = pygame.display.set_mode(size) ball = pygame.image.load("intro_ball.gif") ballrect = ball.get_rect() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speed) if ballrect.left < 0 or ballrect.right > width: speed[0] = -speed[0] if ballrect.top < 0 or ballrect.bottom > height: speed[1] = -speed[1] screen.fill(black) screen.blit(ball, ballrect) pygame.display.flip()
Out[2]:
pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html
In [0]: