且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

统计运算| 学习笔记

更新时间:2022-09-06 18:10:36

开发者学堂课程【Python 科学计算库 NumPy 快速入门统计运算学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/605/detail/8822


统计运算


内容简介:

一、统计指标函数

二、返回最大值、最小值所在位置


一、统计指标

min, max, mean, median, var,  

stdnp.函数名

ndarray.方法名

在数据挖掘/机器学习领域,统计指标的值也是我们分析问题的一种方式。常用的指标如下:·

np.min(a[, axis, out, keepdims])

Return the minimum of an array or minimum along an axis.  

np.max(a[, axis, out, keepdims])   Return the maximum of an array or maximum along an axis.

np.median(a[, axis, out, overwrite. ,input, keepdims)

o Compute the median along the specified axis.

np.mean(a[, axis, dtype, out, keepdims])

o Compute the arithmetic mean along the specified axis.

np.std(a[, axis, dtype, out, ddof, keepdims)

o Compute the standard deviation along the specified axis.

np.var(a[, axis, dtype, out, ddof, keepdims])

o Compute the variance along the specified axis.


二、返回最大值、最小值所在位置

股票涨跌幅统计运算

进行统计的时候,axis 轴的取值并不一定, Numpy 中不同的 API 轴的值都不一样,在这里,axis 0代表列,axis 1代表行去进行统计

#接下来对于这4只股票的4天数据,进行一些统计运算

#指定行去统计

print("前四只股票前四天的最大涨幅

{}”.format(np.max(temp, axis=1)))

# 使用min, std, mean

print("前四只股票前四天的最大跌幅

{}". format(np.min(temp, axis=1)))

print("前四只股票前四天的波动程度

{}" . format(np.std(temp, axis=1)))

print("前四只股票前四天的平均涨跌幅

{}”. format (np. mean(temp, axis=1)))

如果需要统计出哪- -只股票在某个交易日的涨幅最大或者最小?

np.argmax(temp, axis=)

np.argmin(temp, axis=)

#获取股票指定哪一天的涨幅最大

print("前四只股票前四天内漲幅最大

{}". format(np. argmax(temp, axis=1)))

print("前四天一天内涨幅最大的股票

{}". format(np. argmax(temp, axis=0))