Skip to content

Instantly share code, notes, and snippets.

@mizunototori
mizunototori / deldup.md
Last active September 20, 2016 02:31
リストから順序を保ったまま重複要素を削除する

重複した要素をもつリストから、その重複要素を削除することを考える。set関数は重複要素を削除できるが、順序が保証されない。

test_data = [1,2,3,4,5,1,2,3] 

下記の方法が計算量も抑えつつ、順序を保持したまま重複要素を削除できる、らしい。()

sorted(set(test_data), key=test_data.index)
@mizunototori
mizunototori / Python
Created September 20, 2016 06:10
Pythonのリストで2回目に出現するときのインデックスを取得する
a = [1,2,3,4,5,1,2,3,4]
^ ^
0 5
target = a[0]
print(a.index(target,1)) # => 5
@mizunototori
mizunototori / checkmkdr.py
Created September 26, 2016 02:00
[Python]ディレクトリがなかったらそのディレクトリを作成
import os
path = 'test_path/'
if not os.path.isdir(test_path): os.makedirs(test_path)
@mizunototori
mizunototori / ts_trim.m
Last active September 27, 2016 01:01
[Matlab] timeserieseオブジェクトから特定の日時をトリミングする
function [ts2, index] = ts_trim(ts1, start_daten, end_daten, utc_hour)
% Returns a subset timeseriese object of a given timeseriese object.
%{
Parameters:
ts1: timeseriese
original timeseriese object
start_daten : datenum
start date time
end_daten : datenum
end date time
@mizunototori
mizunototori / separate_list.py
Last active September 27, 2016 04:13
[Python] リストをインデックスを用いて2つに分離する
import numpy as np
def separate_list(arr, start, end):
if type(arr) is np.ndarray:
arr_ext = arr[start:end]
arr_res = np.r_[arr[0:start], arr[end:-1]]
elif type(arr) is list:
arr_ext = arr[start:end]
arr_res = arr[0:start] + arr[end:-1]
return [arr_ext, arr_res]
@mizunototori
mizunototori / matlab_unittest.md
Created September 29, 2016 11:02
[Matlab] 単体テスト
  • テストしたい関数
function roots = quadraticSolver(a, b, c)
	% quadratic equation a*x^2 + b*x + c = 0

	if ~isa(a, 'numeric') || ~isa(b, 'numeric') || ~isa(c, 'numeric')
		error('quadraticSolver: InputMustBeNueric', ...
		'Coeficcients must be numeric.')
	end
@mizunototori
mizunototori / execute_conthistory.md
Created October 24, 2016 02:58
[bash] historyから連番で実行

history の531-533を実行したい時

$ history
531  cp A B 
532  cp B C
533  cp C A

evalとfcを組み合わせて、連番実行できる

@mizunototori
mizunototori / low_sampling.m
Created November 4, 2016 04:44
[matlab]timeseriese object: 1min to 1hour sampling , 1分値を1時間値に
function data_1hour = low_sampling(data_1min)
sdn = data_1min.Time;
val = data_1min.Data;
sdn_start = floor(sdn(1));
sdn_end = ceil(sdn(end));
% Create a series with minimal rounding errors
sdn_hourly = bsxfun( @plus, (sdn_start:sdn_end), transpose((0:23)/24) );
@mizunototori
mizunototori / low_sampling.py
Last active November 4, 2016 06:55
[python] 1-min to 1-hour 1分値を1時間値に
def low_sampling(data_1min):
delt = len(data_1min)/24;
data_1hour = [np.mean(data_1min[delt*i:delt*(i+1)]) for i in range(0,23)];
return data_1hour;
@mizunototori
mizunototori / tutorial_sbcl.md
Created January 11, 2017 05:22
SBCL hello world

common lisp 実行手順

Hello world

;;; hello.lisp
(prin1 "Hello world!")

コンパイル&実行