Skip to content

Instantly share code, notes, and snippets.

View BrambleXu's full-sized avatar

BrambleXu BrambleXu

View GitHub Profile
import math, gzip, pickle
import numpy as np
import random
import torch
from torch import tensor
from torch.nn import init
from fastai import datasets
import numpy as np
import matplotlib.pyplot as plt
# random seed to make sure reimplement
np.random.seed(0)
# the real model line
def g(x):
return 0.1 * (x + x**2 + x**3)
import numpy as np
import matplotlib.pyplot as plt
# random seed to make sure reimplement
np.random.seed(0)
# the real model line
def g(x):
return 0.1 * (x + x**2 + x**3)
import math
import numpy as np
import matplotlib.pyplot as plt
# read data
data = np.loadtxt("non_linear_data.csv", delimiter=',', skiprows=1)
train_x = data[:, 0:2]
train_y = data[:, 2]
# plot data points
import numpy as np
import matplotlib.pyplot as plt
# read data
data = np.loadtxt("non_linear_data.csv", delimiter=',', skiprows=1)
train_x = data[:, 0:2]
train_y = data[:, 2]
# plot data points
# plt.plot(train_x[train_y == 1, 0], train_x[train_y == 1, 1], 'o')
x1 x2 y
0.54508775 2.34541183 0
0.32769134 13.43066561 0
4.42748117 14.74150395 0
2.98189041 -1.81818172 1
4.02286274 8.90695686 1
2.26722613 -6.61287392 1
-2.66447221 5.05453871 1
-1.03482441 -1.95643469 1
4.06331548 1.70892541 1
import numpy as np
import matplotlib.pyplot as plt
# read data
data = np.loadtxt("linear_data.csv", delimiter=',', skiprows=1)
train_x = data[:, 0:2]
train_y = data[:, 2]
# initialize parameter
theta = np.random.randn(3)
x1 x2 y
153 432 0
220 262 0
118 214 0
474 384 1
485 411 1
233 430 0
396 321 1
484 349 1
429 259 1
class Solution:
def removeDuplicates(self, nums: List[int]) -> int:
if len(nums) == 0: return 0
if len(nums) == 1: return 1
# nums = [0,0,1,1,1,2,2,3,3,4]
j = 1 # slover pointer, only move when meet unique number
for i in range(1, len(nums)): # faster pointer, i will iterate over all element in nums
if nums[i] != nums[i-1]: # when nums[i] is a unique number, assign it to nums[j]
nums[j] = nums[i]
var fs = require('fs');
var text = fs.readFileSync('./unicode_plane.txt');
var lines = text.toString().split('\n')
for (i=0; i < lines.length; i++) {
// console.log(lines[i].split(' '));
unicode_char = lines[i].split(' ')[0];
count = lines[i].split(' ')[1];
// test for not use spread operator