![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
numpy
云金杞
量化研究员\CTA量化基金经理,金融硕士,CIIA,CFP,FRM,CFA,擅长使用python进行数据分析和建模,熟练使用backtrader、tbquant等量化平台。
展开
-
numpy重新学习系列-numpy的四则运算(13)
import numpy as npa = np.array( [20,30,40,50] )b = np.arange(1,5)print("a is ",a,"\n")print("b is ",b,"\n")# 从加减乘除等基本运算中,可以看到,都是numpy中对应的元素的运算print("a+b",a+b,"\n")print("a-b",a-b,"\n")print("...原创 2019-11-10 20:00:18 · 497 阅读 · 0 评论 -
numpy重新学习系列-如何设置numpy的打印信息输出量(12)
import numpy as npimport sysnp.set_printoptions(threshold=sys.maxsize)这个其实相对来说非常简单,只需要三行代码就可以实现。按照系统最大的输出信息量来打印出来。sys.maxsize是一个数字,在ubuntu18.04的系统中,打印出来是:print(sys.maxsize)922337203685477...原创 2019-11-10 19:39:29 · 1045 阅读 · 0 评论 -
numpy重新学习系列(11)---如何用np.linspace生成等间距的N个数字
作用:1. 通过特定的间隔,返回均匀分布的array2. 根据需要多少的数字,通过计算相应的间隔,返回包含这么多数字的均匀分布的array3. 结尾的数字可以选择包含,也可以选择不包含参数:start 这个序列开始的值stop 这个序列结束的值,除非参数endpoint=False,才不会是最终的值;在endpoint=False的时候,这个序列包含num+1个数字的前nu...原创 2019-10-31 20:37:30 · 2417 阅读 · 0 评论 -
numpy重新学习系列(10)---如何用np.arange生成均匀间隔分布的array
'''numpy.arangenumpy.arange([start, ]stop, [step, ]dtype=None)Return evenly spaced values within a given interval.Values are generated within the half-open interval [start, stop) (in other word...原创 2019-10-31 20:13:32 · 2110 阅读 · 0 评论 -
numpy重新学习系列(9)---如何用np.empty_like创建一个新的和原来array形状一样的,但是未初始化的array
用法参考numpy.zeros_like,参数几乎一样。原创 2019-10-30 21:18:36 · 5528 阅读 · 0 评论 -
numpy重新学习系列(8)---如何用np.empty创建一个未初始化的array
# 用法几乎和np.ones,np.zeros一样# 参考np.zeros的用法# 比较值得探索的是,初始化的值,是否一样import numpy as np原创 2019-10-30 21:13:44 · 4593 阅读 · 1 评论 -
numpy重新学习系列(7)---如何用np.ones_like创建一个新的和原来array形状一样的,但是元素为1的新的array
# 用法和numpy.zeros_like一样# 具体用法参考:numpy.zeros_like原创 2019-10-30 21:03:34 · 1044 阅读 · 0 评论 -
numpy重新学习系列(6)---如何用np.ones创建一个新的array,里面元素是1
'''numpy.onesnumpy.ones(shape, dtype=None, order='C')[source]Return a new array of given shape and type, filled with ones.Parametersshape int or sequence of intsShape of the new array, e....原创 2019-10-30 20:59:21 · 1121 阅读 · 0 评论 -
numpy重新学习系列(5)---如何用np.zeros_like创建一个新的和原来array形状一样的,但是元素为0的新的array
'''numpy.zeros_likenumpy.zeros_like(a, dtype=None, order='K', subok=True, shape=None)[source]Return an array of zeros with the same shape and type as a given array.Parametersa array_like ...原创 2019-10-28 20:12:21 · 2043 阅读 · 0 评论 -
numpy重新学习系列(4)---如何用np.zeros创建填充元素为0的array
### 创造数字为0的array'''np.zeros的用法numpy.zerosnumpy.zeros(shape, dtype=float, order='C')Return a new array of given shape and type, filled with zeros.Parametersshape int or tuple of ints ...原创 2019-10-27 12:19:49 · 3831 阅读 · 0 评论 -
numpy重新学习系列(3)---如何创建一个array-四种从其他形式转化成array的方法
numpy有几种方法可以创建array数据结构。第一种是转换,把python的list,tuple,或者pandas的series或者dataframe转化为array.# 转换成array的几种方法import numpy as npimport pandas as pdarray_from_list=np.array([1,2,3,4,5,6])print("array...原创 2019-10-24 21:29:01 · 733 阅读 · 0 评论 -
numpy重新学习系列(2)---numpy的属性
先决知识:1、要熟悉一些python的基本语法2、如果想要运行本文的案例,需要你先安装一些软件;基础知识:numpy主要的结构是同种的多维的数据类型;它是一些元素的目录表,这些元素通常是数字,同样的数据类型,被非负数的数字,以index标记。numpy的类主要是ndarray,有时候也用array表示。python的array.array只能处理一维的数据,并且只有少量的...原创 2019-10-23 20:56:27 · 259 阅读 · 0 评论 -
numpy重新学习系列(1)---重新认识numpy
学习使用python三年多的时间了,在平常的生活中,在日常的工作中,或多或少都要使用到numpy,pandas,matplotlib,scipy,plotly等模块,却发现,对这些模块并没有能够达到精通的程度,仅仅了解了其中某些函数的用法。希望通过这次的学习能够进一步夯实python的基础。这次的python学习之旅,将会以场景化应用为主,覆盖尽可能多的函数,精读,希望每...原创 2019-10-20 19:55:30 · 291 阅读 · 0 评论 -
empyrical 模块的学习与分析 note4
stats.py里面封装了大量的计算绩效和风险的指标,但是估计这个写的时间比较早,用了大量的numpy,而对pandas使用较少,如果使用pandas的高级功能来封装这些函数的话,总体的代码量可能大大较少###########################################################################从future模块引入division,在py...翻译 2018-06-03 15:24:57 · 3062 阅读 · 0 评论 -
python-numpy-方差、相关系数
# Array of differences to mean: differencesdifferences=versicolor_petal_length-np.mean(versicolor_petal_length)# Square the differences: diff_sqdiff_sq=np.square(differences)# Compute the mean转载 2018-03-16 20:18:32 · 5287 阅读 · 0 评论 -
python-numpy-伯努利试验模拟-np.random.binomial--自定义bins的直方图
def perform_bernoulli_trials(n, p): """Perform n Bernoulli trials with success probability p and return number of successes.""" # Initialize number of successes: n_success n_success = ...翻译 2018-03-16 20:50:25 · 4561 阅读 · 0 评论 -
python-numpy-泊松分布
# Draw 10,000 samples out of Poisson distribution: samples_poissonsamples_poisson=np.random.poisson(10,size=10000)# Print the mean and standard deviationprint('Poisson: ', np.mean(samples_pois翻译 2018-03-17 09:52:53 · 10227 阅读 · 0 评论 -
python-numpy-正态分布的模拟--pdf图--cdf图---正态分布的拟合
# Draw 100000 samples from Normal distribution with stds of interest: samples_std1, samples_std3, samples_std10samples_std1=np.random.normal(20,1,size=100000)samples_std3=np.random.normal(20,3,size=...翻译 2018-03-17 10:02:48 · 16921 阅读 · 5 评论 -
python-numpy-指数分布模拟
def successive_poisson(tau1, tau2, size=1): # Draw samples out of first exponential distribution: t1 t1 = np.random.exponential(tau1, size=size) # Draw samples out of second exponential d...翻译 2018-03-17 10:27:52 · 8358 阅读 · 0 评论 -
python-numpy-指数分布
# Seed random number generatornp.random.seed(42)# Compute mean no-hitter time: tautau = np.mean(nohitter_times)# Draw out of an exponential distribution with parameter tau: inter_nohitter_timei...翻译 2018-03-18 17:40:46 · 4325 阅读 · 0 评论 -
python-numpy-相关性、回归、画图-np.polyfit(x,y,deg=1)
from scipy import stats# Plot the illiteracy rate versus fertility_ = plt.plot(illiteracy, fertility, marker='.', linestyle='none')# Set the margins and label axesplt.margins(0.02)_ = plt.xla翻译 2018-03-18 18:57:57 · 6986 阅读 · 0 评论 -
python-numpy-bootstrap模拟
for i in range(50): # Generate bootstrap sample: bs_sample bs_sample = np.random.choice(rainfall, size=len(rainfall)) # Compute and plot ECDF from bootstrap sample x, y = ecdf(bs_samp...翻译 2018-03-18 19:10:48 · 1323 阅读 · 0 评论 -
numpy标准化数据的一个方法(belief[hallway ==1] *= 3)
import numpy as nphallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])belief = np.array([0.1] * 10)belief[hallway ==1] *= 3belief / sum(belief)原创 2018-04-09 21:49:14 · 704 阅读 · 0 评论 -
rqalpha安装后使用报错:numpy.core.multiarray failed to import
win10,python3,anaconda3------4.4.0解决办法:1、pip uninstall numpy2、pip install numpy卸载重装之后就变得正常了。原创 2018-05-07 18:27:04 · 403 阅读 · 0 评论 -
python-numpy-计算分位数
# Specify array of percentiles: percentilespercentiles = np.array([2.5, 25, 50, 75, 97.5])# Compute percentiles: ptiles_versptiles_vers = np.percentile(versicolor_petal_length, percentiles)# Pri翻译 2018-03-16 10:56:07 · 28899 阅读 · 0 评论