Skip to content

Instantly share code, notes, and snippets.

@elnikkis
elnikkis / pdfmergetwoside.py
Created April 18, 2024 13:03
PDF分割とマージ
'''
PDFをマージして見開きにする
'''
import subprocess
import tempfile
from pathlib import Path
def main(args):
with tempfile.TemporaryDirectory() as tmpdir:
@elnikkis
elnikkis / qcmd.sh
Created February 1, 2024 17:05
京大Slurm用qcmd
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: [Q=QueueName] [P=NProcs] [T=NThreads] [C=NCpus] [M=Memory (GB)] [W=WallTime (hour)] [J=JobName] [O=LogDir] bash $0 [-I|command]"
exit 1
fi
# Set default values
R="p=${P:=1}:t=${T:=1}:c=${C:=1}:m=${M:=3}G"
@elnikkis
elnikkis / dbscan.py
Created March 23, 2022 11:00
DBSCANの全距離対計算する版実装
'''Implement DBSCAN clustering algorithm'''
import numpy as np
from scipy.spatial import distance
from scipy.sparse.csgraph import connected_components
def dbscan(X, eps=0.5, minPts=2):
X = np.array(X)
if X.ndim != 2:
@elnikkis
elnikkis / typednamedtuple.py
Created July 15, 2020 08:52
Typed namedtuple
# -*- coding: utf-8 -*-
from collections import namedtuple
def typednamedtuple(typename, field_names, field_types):
'''Typed namedtuple
An implementation of typed namedtuple.
@elnikkis
elnikkis / convert_graph.py
Created July 12, 2019 10:55
ノードID変換
# -*- coding: utf-8 -*-
'''
edgelistとlabellistを0始まりのIDに変換する
'''
import os
import sys
#from snlocest.largedict import LargeDict
@elnikkis
elnikkis / main.c
Created June 9, 2019 13:04
三目並べ
#include <stdio.h>
/*
* 三目並べを作る
* */
#define WIDTH 3
#define HEIGHT 3
#define BLANK 0
# coding: utf-8
'''
はねろコイキングのとっくんのCPテーブルをダウンロード
'''
import os
import urllib.request
import bs4
# -*- coding: utf-8 -*-
import random
def markov(n, p):
state = True
for i in range(n):
x = random.random()
if p > x:
state = not state
# -*- coding: utf-8 -*-
'''
Label Propagationを実装した
'''
import numpy as np
import scipy as sp
import sklearn.datasets
import sklearn.metrics as metrics
# coding:utf-8
def print_mat(mat):
for row in mat:
for c in row:
print(c, end=", ")
print()
def gauss_jordan(mat):
n = len(mat)