重複した要素をもつリストから、その重複要素を削除することを考える。set関数は重複要素を削除できるが、順序が保証されない。
test_data = [1,2,3,4,5,1,2,3]
下記の方法が計算量も抑えつつ、順序を保持したまま重複要素を削除できる、らしい。()
sorted(set(test_data), key=test_data.index)
重複した要素をもつリストから、その重複要素を削除することを考える。set関数は重複要素を削除できるが、順序が保証されない。
test_data = [1,2,3,4,5,1,2,3]
下記の方法が計算量も抑えつつ、順序を保持したまま重複要素を削除できる、らしい。()
sorted(set(test_data), key=test_data.index)
| a = [1,2,3,4,5,1,2,3,4] | |
| ^ ^ | |
| 0 5 | |
| target = a[0] | |
| print(a.index(target,1)) # => 5 |
| import os | |
| path = 'test_path/' | |
| if not os.path.isdir(test_path): os.makedirs(test_path) |
| 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 |
| 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] | |
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
history の531-533を実行したい時
$ history
531 cp A B
532 cp B C
533 cp C Aevalとfcを組み合わせて、連番実行できる
| 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) ); |
| 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; |