如何获取NumPy数组的描述性统计信息?

如何获取NumPy数组的描述性统计信息?,第1张

如何获取NumPy数组描述性统计信息?

这不是一个很好的解决方案,但可以完成工作。问题在于,通过指定多个dtype,您实际上是在制作一个元组的1D数组(实际上是

np.void
),由于它包含多个不同的类型(包括),因此无法用统计信息进行描述。字符串。

可以通过两轮阅读或将熊猫与配合使用来解决

read_csv

如果您决定坚持

numpy

import numpy as npa = np.genfromtxt('sample.txt', delimiter=",",unpack=True,usecols=range(1,9))s = np.genfromtxt('sample.txt', delimiter=",",unpack=True,usecols=0,dtype='|S1')from scipy import statsfor arr in a: #do not need the loop at this point, but looks prettier    print(stats.describe(arr))#Output per print:DescribeResult(nobs=6, minmax=(0.34999999999999998, 0.70999999999999996), mean=0.54500000000000004, variance=0.016599999999999997, skewness=-0.3049304880932534, kurtosis=-0.9943046886340534)

请注意,在此示例中,最终数组具有

dtype
as
float
,not
int
,但可以使用(如果需要)轻松地将其转换为int
arr.astype(int)



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5668768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存