Skip to content

Instantly share code, notes, and snippets.

View zhpmatrix's full-sized avatar
🎯
Focusing

张大千 zhpmatrix

🎯
Focusing
View GitHub Profile
import tensorflow as tf
from numpy import *
from random import randint
max_length = 2
batch_size = 3
label = array([[[0,0] for _ in range(max_length)] for _ in range(batch_size)])
for i in range(batch_size):
for j in range(max_length):
import tensorflow as tf
from numpy import *
from random import randint
max_length = 3
batch_size = 5
targets = array([[1 for _ in range(max_length)] for _ in range(batch_size)])
logits = array([[[randint(0,10)/10,randint(0,10)/10] for _ in range(max_length)] for _ in range(batch_size)])
sequence_length = array([randint(1,max_length) for _ in range(batch_size)])
@zhpmatrix
zhpmatrix / cal.py
Created October 21, 2018 04:43
计算无穷级数-遇到越界和除零错误(级数展开还是遇到越界问题)
import math
import numpy as np
def get_cosh(x):
N = 100000
t = 0.0
for i in range(0, N):
t += math.pow(x,2*i)*1.0/math.factorial(2*i)*1.0
return 2 * t * 1.0 / 2
@zhpmatrix
zhpmatrix / nms_fast.m
Created May 22, 2018 08:42 — forked from quantombone/nms_fast.m
blazing fast nms (non-maximum suppression)
function top = nms(boxes, overlap)
% top = nms_fast(boxes, overlap)
% Non-maximum suppression. (FAST VERSION)
% Greedily select high-scoring detections and skip detections
% that are significantly covered by a previously selected
% detection.
% NOTE: This is adapted from Pedro Felzenszwalb's version (nms.m),
% but an inner loop has been eliminated to significantly speed it
% up in the case of a large number of boxes
% Tomasz Malisiewicz (tomasz@cmu.edu)
@zhpmatrix
zhpmatrix / argparse.py
Created March 5, 2018 04:13
How to use argparse module to achieve my goals?
import argparse
parser = argparse.ArgumentParser(description='Main Application')
parser.add_argument('--n',type=str,default='magic',help='name of dataset')
parser.add_argument('--m',type=str,default='m11',help='method name(11,21,22)')
parser.add_argument('--dr',type=int,default=1,help='random state of train_test_split')
args = parser.parse_args()
train_X, test_X, label_X, label_Y = get_data(args.n, args.dr)
@zhpmatrix
zhpmatrix / dot_product_intrinsic.c
Created December 4, 2017 09:02
intrinsic编程:优化C/C++代码,不写Assembly
#include <stdio.h>
#include <xmmintrin.h>
int main(){
short in1[] = {1,2,3,4};
short in2[] = {2,3,4,5};
int out1;
int out2;
__m64 m1;
__m64 m2;
__m128 m128;
from retrying import retry
from random import random
@retry(stop_max_attempt_number=7)
def do():
if random() > 0.5:
print('Success!')
else:
print('Fail!')
raise
@zhpmatrix
zhpmatrix / try
Created September 24, 2017 06:55
python中try/except/else/finally语句的完整格式如下所示:
try:
Normal execution block
except A:
Exception A handle
except B:
Exception B handle
except:
Other exception handle
else:
import numpy as np
def drop_first_last(grades):
first, *middle, last = grades
return middle
def args(*args):
for value in args:
print(value)
def dropout(x, level, noise_shape=None, seed=None):
"""Sets entries in `x` to zero at random, while scaling the entire tensor.
# Arguments
x: tensor
level: fraction of the entries in the tensor
that will be set to 0.
noise_shape: shape for randomly generated keep/drop flags,
must be broadcastable to the shape of `x`