Skip to content

Instantly share code, notes, and snippets.

@anyuzx
anyuzx / 0_reuse_code.js
Created Feb 24, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@anyuzx
anyuzx / lammps_compute_gyration.md
Last active Feb 28, 2017
walk through LAMMPS compute_gyration.h and compute_gyration.cpp
View lammps_compute_gyration.md

Notes about LAMMPS source codes, compute_gyration.h and compute_gyration.cpp.

compute_gyration.h

#ifdef COMPUTE_CLASS

ComputeStyle(gyration,ComputeGyration)

#else
@anyuzx
anyuzx / acf.py
Created Sep 28, 2016
autocorrelation in python
View acf.py
# Since there is no real autocorrelation compute function in python and numpy
# I write my own one
import numpy as np
# Suppose data array represent a time series data
# each element represent data at given time
# Assume time are equally spaced
def acf(data):
mean = np.mean(data)
@anyuzx
anyuzx / save_sparse_matrix.py
Created Oct 3, 2016
save spicy sparse matrix/array object to file
View save_sparse_matrix.py
from scipy import sparse, io
m = sparse.csr_matrix([[0,0,0],[1,0,0],[0,1,0]])
m # <3x3 sparse matrix of type '<type 'numpy.int64'>' with 2 stored elements in Compressed Sparse Row format>
io.mmwrite("test.mtx", m)
del m
newm = io.mmread("test.mtx")
newm # <3x3 sparse matrix of type '<type 'numpy.int32'>' with 2 stored elements in COOrdinate format>
@anyuzx
anyuzx / extract_pid.md
Created Feb 19, 2017
extract pid from ps aux command
View extract_pid.md
ps aux | grep name | grep -v grep
ps aux | grep name | grep -v grep | awk '{print $2}'
View pivot_algorithm_python.py
import numpy as np
import timeit
from scipy.spatial.distance import cdist
# define a dot product function used for the rotate operation
def v_dot(a):return lambda b: np.dot(a,b)
class lattice_SAW:
def __init__(self,N,l0):
self.N = N
View mdrnn_blog_block3.py
anisotropy = False
learning_rate = 0.005
batch_size = 200
h = 10
w = 10
channels = 1
x = tf.placeholder(tf.float32, [batch_size, h, w, channels])
y = tf.placeholder(tf.float32, [batch_size, h, w, channels])
linear_map = np.random.rand(h,w)
View mdrnn_blog_block4.py
def next_batch_nonlinear_map(bs, h, w, anisotropy=True):
# ... same code ...
y.append(np.dot(item, item)) # only changes here
# ... same code ...
View test.py
import numpy as np
x = np.random.rand(1000)
y = np.random.rand(1000)
@anyuzx
anyuzx / random_walk_2d.py
Last active Sep 23, 2019
Generate 2D random walk trajectory
View random_walk_2d.py
import numpy as np
def walk(n):
# check if the number of steps is an integer
if int(n) != n:
print('number of steps should be an integer')
return None
# the initial position is (0,0)
xy_0 = np.array([0.0, 0.0])
# generate displacements of each step