Skip to content

Instantly share code, notes, and snippets.

View lhsfcboy's full-sized avatar
🌴
On vacation

Mike Hongshuai Luo lhsfcboy

🌴
On vacation
  • Feicheng,China
View GitHub Profile
@lhsfcboy
lhsfcboy / simulte_unknown_distribution.py
Created June 26, 2017 01:57
模拟未知的分布并绘图展示
#!pip install functools
from functools import partial
import numpy
from matplotlib import pyplot
# Define a PDF
x_samples = numpy.arange(-3, 3.01, 0.01)
PDF = numpy.empty(x_samples.shape)
PDF[x_samples < 0] = numpy.round(x_samples[x_samples < 0] + 3.5) / 3
PDF[x_samples >= 0] = 0.5 * numpy.cos(numpy.pi * x_samples[x_samples >= 0]) + 0.5
@lhsfcboy
lhsfcboy / gcd_and_lcm.py
Last active June 26, 2017 01:54
GCD and LCM functions in Python
"""最小公倍数与最大公约数"""
def gcd(*numbers):
"""Return the greatest common divisor of the given integers"""
from fractions import gcd
return reduce(gcd, numbers)
def lcm(*numbers):
"""Return lowest common multiple."""
def lcm(a, b):