低,高= fn_range(* args) TypeError:无法解压缩不可迭代的int对象 我真的应该如何声明对 integrate.nquad 中的多重积分的 [(0,1)** n] 支持?文档没有给出匹配的示例解决方案由于评论部分已超载,因此发布一些评论作为答案.(1)我想用(0,1)** 2 来表示乘积(0,1)x(0,1),即单位平方.我认为Python无法理解这一点.如果您需要告诉nquad积分的范围是单位平方,我想您需要说其他一些方式.(2)请发布您实际使用的函数的公式,即c(u).请记住,当您省略细节或将其推迟到链接时,只会使他人更难以理解,因此获得有效帮助的可能性也较小.(3)熵计算的积分范围是概率函数的所谓支持,即,概率大于零的集合.c(u)的支持是什么?这就定义了集成领域.在教科书或其他说明中,习惯上都说域是R或(-inf,+ inf)或以其他方式使其模棱两可,但是对于实际计算,您需要将其缩减为支持范围.很抱歉,我无法提供更多帮助,这是一个有趣的问题.I attempt the following multiple integral in the code below for a higher-than-bivariate version (n=2) of a copula density function, c(u1,u2). In other words, n>2 dimensions.import numpy as npfrom scipy import integratedef H(theta): c = lambda *us: ((1+theta)*np.prod(*us)**(-1-theta)) * (np.sum(*us **(-theta))-1)**(-1/theta-2) return -integrate.nquad( func = lambda *us : c(*us)*np.log(c(*us)), ranges = (0,1)**n, args = (theta,) )[0]theta, n = 1, 3print(H(theta))where *us represents the arbitrary number of u's I can pass in. The second input argument to integrate.nquad, which is ranges=(0,1)**n, is the [0,1] support of the integral due to n dimensions of u's, which I try to explain in the derivation above. However, this part of the code gives the following error.TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'If I change this input to ranges=(0,1) by removing the exponent n as suggested by the error, then I get a different error:low, high = fn_range(*args)TypeError: cannot unpack non-iterable int objectHow am I really supposed to declare the [(0,1)**n] support for a multiple integral in integrate.nquad? The documentation does not give a matching example. 解决方案 Posting some comments as an answer since the comments section is getting overloaded.(1) I think by (0, 1)**2 you mean to say the product (0, 1) x (0, 1), i.e., the unit square. I don't think Python is going to understand that. If you need to tell nquad that the domain of integration is the unit square, I think you need to say that some other way.(2) Please post the formula for the function you are actually working with, namely c(u). Bear in mind that when you omit details or defer them to links, it only makes it harder for others to understand and therefore less likely that you can get effective help.(3) The domain of integration for entropy calculation is the so-called support of the probability function, that is, the set on which the probability is greater than zero. What is the support of c(u)? That defines the domain of integration. It is customary in textbooks or other expositions to say the domain is R or (-inf, +inf) or otherwise leave it ambiguous, but for an actual calculation you need to cut it down to the support.I'm sorry I can't be more helpful, it's an interesting question. 这篇关于使用scipy.integrate.nquad的多重积分-Lambda函数的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 15:54