Skip to content

Instantly share code, notes, and snippets.

@yuugit
yuugit / dataframe.py
Created July 26, 2013 11:49
numpyが古くてpandasが使えないけどDataFrameっぽいものが使いたいので書く。 まだ中身はスカスカだけど……
# -*- coding: utf-8 -*-
import csv
import numpy as np
def cbind(*dfseq):
u"""行数が同じである複数のデータフレームを渡された順番に結合した
1つのデータフレームにして返す。
"""
@yuugit
yuugit / python_template.py
Created July 26, 2013 02:36
a python template for auto-insert
# -*- coding: utf-8 -*-
def main():
(options, args) = parse_options()
def parse_options():
import optparse
parser = optparse.OptionParser()
@yuugit
yuugit / adj_iter.py
Created July 18, 2013 06:01
an util for networkx
def adj_iter(network, x):
u"""network のノード x に隣接するエッジのイテレータを返す。
素の edges_iter は存在しないノードに対してエラーを吐き面倒なので
このジェネレータ関数で回避する。
"""
if network.has_node(x):
for t in network.edges_iter(x):
yield t
else:
@yuugit
yuugit / mandelbrot.R
Created June 17, 2013 23:29
Mandelbrot
initial.mandel <- function(input) {
x <- seq(input$xmin, input$xmax, length.out=input$xresol)
y <- seq(input$ymin, input$ymax, length.out=input$yresol)
outer(x, y, function(x, y) complex(real=x, imaginary=y))
}
calc.mandel <- function(c) {
z <- list(c) # z_1 = c の計算(?)
for (i in 1:input$niter) {
z[[i+1]] <- z[[i]]^2 + c # z_{i+1} = z_i^2 + c の計算
@yuugit
yuugit / probs
Last active December 18, 2015 13:59
probability
expected.x <- function(d, a, h) {
sum(sapply(0:h, function(y) prob.justy(d, a, h, y)) * 0:h)
}
prob.xormore <- function(d, a, h, x) {
if (d >= h && min(a, h) >= x)
sum(prob.justy.nocheck(d, a, h, x:min(a, h)))
else {
0
}
}
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,