布里渊多样性指数

2024-09-29 17:18:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python计算Brillouin的多样性指数,根据使用pandas和numpy的列“a”。但出了点事。你知道吗

import pandas as pd
import numpy as np
def Brillouin_Index(x):
    for i in range(len(x)):
        x["Brillouin_Index"] = (np.log10(np.math.factorial(np.sum(x))) - np.sum(np.log10(np.math.factorial(x[i])))) / np.sum(x)
        return x
a = list("ABCDEADECS")
b = [12,23,12,12,32,34,21,2,10,5]
c = {"a":a,"b":b}
data = pd.DataFrame(c)
data
data.groupby("a").apply(Brillouin_Index)

我执行了上面的代码,有两个错误。你知道吗

TypeError: cannot convert the series to <class 'int'>
AttributeError: 'int' object has no attribute 'log10'

具体公式见以下链接Brillouin’s Diversity Index

我用其他软件计算每组的数值

  1. HƏA=0.2965
  2. H_B=0
  3. HƏC=0.264
  4. 高度=0.259
  5. HƏE=0.08085
  6. H_S=0

非常感谢!你知道吗


Tags: importnumpypandasdataindexasnpmath
1条回答
网友
1楼 · 发布于 2024-09-29 17:18:50

我用R来计算布里渊的分集指数组。组代码如下:

Brillouin_Diversity_Index <- function(x)
{  N <- sum(x)

 (log10(factorial(N)) - sum(log10(factorial(x)))) / N

}

dt <- data.table(x = c("A","B","C","D","E","A","D","E","C","S"),
y = c(12,23,12,12,32,34,21,2,10,5))
dt[,Brillouin_Diversity_Index(y),by = .(x)]
  1. 第1版
  2. 甲0.23021887
  3. 亿英镑
  4. 0.2641221加元
  5. 直径0.25909105
  6. 传真:0.08085185
  7. 0.00000000新加坡元

相关问题 更多 >

    热门问题