自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(30)
  • 收藏
  • 关注

原创 Logarithmic returns in pandas dataframe

df['pct_change'] = df.price.pct_change()df['log_return'] = np.log(1 + df.pct_change)pct_change: percentage change

2019-10-22 14:14:42 493

原创 Dijkstra’s shortest path algorithm

import sys class Graph(): def __init__(self, vertices): self.V = vertices #number of vertices self.graph = [[0 for column in range(vertices)] #used for adjacent matr...

2019-10-21 09:59:13 166

原创 python 制作GIF

def creat_gif(image_list,gif_name): frames=[] for image_name in image_list: frames.append(imageio.imread(image_name)) imageio.mimsave(gif_name,frames,'GIF',duration=0.2)ima...

2019-10-19 11:09:15 101

原创 将list中各个元素逐行输出

with open ('corpus.csv', 'w') as fo: for d in corpus: fo.write(str(d) + '\n')

2019-10-17 13:22:27 4452

原创 scipy.sparse.coo_matrix 稀疏矩阵存储数据

# Constructing an empty matrixfrom scipy.sparse import coo_matrixcoo_matrix((3, 4), dtype=np.int8).toarray()array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=int8)row = n...

2019-10-17 13:07:27 338

原创 Install PyTorch in windows (anaconda)

https://pytorch.org/在Pytorch的主页选择自己所要安装的版本,直接在anaconda prompt中输入命令即可。“conda install pytorch torchvision cudatoolkit=10.1 -c pytorch”

2019-10-14 17:26:35 146

原创 python画棋盘

import matplotlibcolor1=(1,1,1)color2=(247/255,220/255,111/255)mat=np.zeros((8,8))for i in range(8): for j in range(8): if (i+j)%2==0: mat[i,j]=1 else: ...

2019-10-11 21:44:02 4048 1

原创 plt.imshow() & plt.pcolor()

import numpy as npimport matplotlib.pyplot as pltepsilon=10E-10;Z=1;N=3def func_px(x,y,z): r=np.sqrt(x**2+y**2+z**2) if r<epsilon: return 0 rho=2*Z*r/N R2p=(1/2/np.sqr...

2019-10-11 20:17:25 2963

转载 Kruskal’s Minimum Spanning Tree Algorithm 最小生成树算法

https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/

2019-10-11 15:55:54 308

原创 Kahn’s algorithm for Topological Sorting 拓扑排序算法

Topological sorting forDirectedAcyclicGraph (DAG)有向无环图 is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a grap...

2019-10-11 15:49:23 265

原创 Breadth First Search or BFS for a Graph 广度优先搜索算法 & Depth First Search or BFS for a Graph 深度优先搜索算

from collections import defaultdictclass Graph: def __init__(self): self.graph = defaultdict(list) def addEdge(self,u,v): self.graph[u].append(v) #print(self.graph...

2019-10-11 14:36:19 282

原创 Radix Sort 基数排序

Idea: sort each digit by counting sort.Start from least significant digit (LSD) - Each digit sort once then done.def counting_sort_by(array,max_rank=None,rank=lambda x:x): if max_rank is None:...

2019-10-11 11:25:17 119

原创 Counting Sort & Counting Sort by Given Rank

def counting_sort(array): max_elem=max(array) counts=[0 for i in range(max_elem+1)] for elem in array: counts[elem]+=1 print(counts) return [i for i in range(len(counts))...

2019-10-10 18:10:20 96

原创 Planar_data_classification_with_one hidden_layer (具有一个隐藏层的平面数据分类, 神经网络/深度学习)

import numpy as npimport matplotlib.pyplot as pltfrom testCases_v2 import *import sklearnimport sklearn.datasetsimport sklearn.linear_modelfrom planar_utils import plot_decision_boundary, sigmo...

2019-10-10 17:04:18 197

原创 a Neural Network with a single hidden layer (具有单个隐藏层的神经网络)

(you can use eithernp.multiply()and thennp.sum()or directlynp.dot()).Note that if you usenp.multiplyfollowed bynp.sumthe end result will be a typefloat, whereas if you usenp.dot, the r...

2019-10-10 14:55:10 440

原创 激活函数的导数

深度学习常用的几种激活函数:sigmoid函数 tanh函数 relu函数和leaky relu: max(0,x), max(0.01x, x)激活函数的导数:1. sigmoid函数:(应用范围较小,常用于binary classification)2.tanh函数 :(性能由于sigmoid)3.relu函数和leaky relu(收敛速度快,计算快,应用...

2019-10-08 19:59:24 443

原创 逻辑回归+神经网络 (识别猫的图像,computer vision)

import numpy as npimport matplotlib.pyplot as pltimport h5pyimport scipyfrom PIL import Imagefrom scipy import ndimagefrom lr_utils import load_dataset%matplotlib inlineProblem Statement: Y...

2019-10-08 16:17:56 420

转载 np.dot(),np.outer(),np.multiply(),*

(1):np.dot()如果碰到的是秩为1的数组,那么执行的是对应位置的元素相乘再相加;如果遇到的是秩不为1的数组,那么执行的是矩阵相乘。但是需要注意的是矩阵与矩阵相乘是秩为2,矩阵和向量相乘秩为1。(2):np.multiply()表示的是数组和矩阵对应位置相乘,输出和输出的结果shape一致。(3):np.outer()表示的是两个向量相乘,拿第一个向量的元素分别与第二个向量所...

2019-10-07 23:05:20 56

原创 Broadcasting and the softmax function in Python

def softmax(x): x_exp = np.exp(x) x_sum = np.sum(x_exp,axis=1,keepdims=True) s = x_exp/x_sum return sx = np.array([ [9, 2, 5, 0, 0], [7, 5, 0, 0 ,0]])print("softmax(x...

2019-10-07 21:21:25 308

原创 Normalizing rows in Python

def normalizeRows(x): x_norm = np.linalg.norm(x,axis=1,keepdims=True) x = x/x_norm return xx = np.array([ [0, 3, 4], [1, 6, 4]])print("normalizeRows(x) = " + str(normalizeRows(...

2019-10-07 21:10:44 204

原创 Reshaping arrays in Python

在计算机科学中,图像通过3D array(length,height,depth=3)来表示。然而,图像作为算法的输入时,需转化成一维列向量(length∗height∗3,1)。def image2vector(image): v = image.reshape((image.shape[0]*image.shape[1]*image.shape[2]),1) return...

2019-10-07 20:59:03 139

原创 Broadcasting in Python

import numpy as npA=np.array([[56,0,4.4,68], [1.2,104,52,8], [1.8,135,99,0.9]])print(A)cal=A.sum(axis=0)#将各列相加print(cal)#cal1=A.sum(axis=1)#将各行相加#print(cal1)percentage=1...

2019-10-07 19:25:11 113

原创 vectorization in python to avoid for-loop

for-loop的计算时间较长,可通过vectorization来提高运算速率。import numpy as npimport timea=np.random.rand(1000000)b=np.random.rand(1000000)tic=time.time()c=np.dot(a,b)#vectorizedtoc=time.time()print("vectorized...

2019-10-04 14:44:21 186

原创 Notes of CFA Level1 READING 41 & 42: Introduction to Risk Management

The major components of an IPS(investment policy statement) typically address the following:Description of Client circumstances, situation, and investment objectives. Statement of the Purpose of th...

2019-10-03 17:53:11 290

原创 Notes of CFA Level1 READING 40: PORTFOLIO RISK AND RETURN: PART II

2019-10-03 17:30:15 234

原创 Notes of CFA Level1 READING 39: PORTFOLIO RISK AND RETURN: PART I

2019-10-03 15:13:34 138

原创 python multiprocessing parallel

分别通过serial和MPI,数值计算pi, 比较计算速率。import sysimport timeimport multiprocessing as mpimport numpy as npnumint=int(sys.argv[1])def integral_pi(numint): integral=0.0 x=np.zeros(numint,floa...

2019-10-03 14:52:08 329

原创 Python中 sys.argv[]的用法简明解释

在Linux terminal中运行python程序时,可以通过命令行输入参数,例如python3 hello.py 100000 10sys.argv[0]就是hello.py程序本身sys.argv[1] 是第一个参数100000sys.argv[2] 是第二个参数10...

2019-10-03 14:44:00 76

原创 在LINUX里面查L1,L2,L3 CACHE

2019-10-02 11:53:16 2086

转载 linux 如何查看硬盘大小,内存大小等系统信息及硬件信息

一、linux CPU大小:cat /proc/cpuinfo二、内存大小:cat /proc/meminfo三、硬盘大小及分区使用:df -h四、其他查看硬件信息的方法:uname -a # 查看内核/操作系统/CPU信息(含x86_64表示32位机器,i686表示32位机器) head -n 1 /etc/issue # 查看操作系统版本,是数字1不是字母L cat /p...

2019-10-01 14:43:35 1353

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除