Skip to content

Instantly share code, notes, and snippets.

View wiccy46's full-sized avatar

Jiajun wiccy46

  • Holoplot
  • Berlin
View GitHub Profile
@wiccy46
wiccy46 / numpy_subset.py
Created July 19, 2019 09:44
[numpy_subset]A collection of different number subsetting #python
"""To get a new array by subsetting columns of different np.ndarray"""
a = np.array([[1,2],[3,4],[5,6]])
b = np.array([[10,20],[30,40],[50,60]])
# Using zip
[(a_s[0], b_s[0]) for a_s, b_s in zip(a,b)]
# A faster way is to concat and ravel, use ('float, float') if float number.
np.c_[a[:,0],b[:,0]].view('i,i').ravel()
@wiccy46
wiccy46 / bandwidth2q.py
Created July 22, 2019 16:21
[bandwidth2q]Convert frequency bandwidth to q factor. #python
# This code covert formant bandwidth to q
import sys
f0 = map(float, sys.argv[1].strip('[]').split(','))
bw = map(float, sys.argv[2].strip('[]').split(','))
q = []
if (not len(f0)==len(bw)):
print "Error: Two arguments need to have the same lenght. "
print 'Usage: First argument list of fundamental frequency, e.g "[19, 299, 449]"'
@wiccy46
wiccy46 / withinErrBar.py
Created July 22, 2019 16:56
[withinErrBar]Within subject error bar #python #DataAnalysis
def within_subject_errorbar(df, ci_r = 1.96):
df["Subject average"] = df.mean(axis = 1)
df_grand_avg = df["Subject average"].mean()
df["New condition1"] = df["condition1"] - df["Subject average"] + df_grand_avg
df["New condition2"] = df["condition2"] - df["Subject average"] + df_grand_avg
std_vo, std_me = df["New condition1"].std(), df["New condition2"].std()
@wiccy46
wiccy46 / dbfft.py
Created July 25, 2019 21:01
[dbfft] Power Spectrum in dB #python #dsp
def dbfft(x, fs, win=None, ref=32768):
"""
Calculate spectrum in dB scale
Args:
x: input signal
fs: sampling frequency
win: vector containing window samples (same length as x).
If not provided, then rectangular window is used by default.
ref: reference value used for dBFS scale. 32768 for int16 and 1 for float
@wiccy46
wiccy46 / printVector.cpp
Created August 9, 2019 09:27
[printVector]Print C++ vector #c++
for (std::vector<int>::const_iterator i = vecName.begin(); i != vecName.end(); ++i)
std::cout << *i << std::endl;
@wiccy46
wiccy46 / get_all_files_name.py
Last active August 12, 2019 16:32
[get_all_files_name]Get all files names into a list #python
import os
file_names = os.listdir("file_path")
@wiccy46
wiccy46 / multichannel_vector_to_matrix.py
Last active August 13, 2019 14:36
[multichannel_vector_to_matrix]Convert a long multichannel audio vector into a n columns numpy array #python #audio
n_columns_ndarray = long_audio_vector.reshape((-1, num_of_channels))
@wiccy46
wiccy46 / [tmux.md]
Last active August 26, 2019 08:50
[tmux_cheatsheet]Useful tmux commands #tmux
## Session Management
Sessions are useful for completely separating work environments. I have a ‘Work’ session and a ‘Play’ session; in ‘Work’, I keep everything open that I need during my day-to-day development, while in ‘Play’, I keep open current open-source gems or other work I hack on at home.
tmux new -s session_name
creates a new tmux session named session_name
tmux attach -t session_name
attaches to an existing tmux session named session_name
tmux switch -t session_name
switches to an existing session named session_name
@wiccy46
wiccy46 / flutter_filler.dart
Created August 28, 2019 15:39
[flutter_filler] Basic filler of a flutter project #dart #flutter
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: MyApp(),
));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
@wiccy46
wiccy46 / 1darray2colvec.py
Last active September 20, 2019 08:10
[1darray2colvec]Convert 1D array to Column Vector in Python #python
a = np.arange(10) # (10, )
a.reshape(-1, 1) # (10, 1)