【发布时间】:2011-04-16 09:33:02
【问题描述】:
所以我想绘制简单的 gamma 函数,但我遇到了一些问题。我的代码是:
#!/usr/bin/env python
# -*- coding: cp1250 -*-
#import math
from scipy.special import *
#from scitools.std import *
from pylab import *
def f1(x):
return gamma(x)
x = linspace(-6, 6, 512)
y1 = f1(x)
# Matlab-style syntax:
plot(x, y1)
xlabel('x')
ylabel('y')
legend(r'$\Gamma(x)$')
grid(True)
show()
我尝试从 math 和 scipy.special 导入 gamma 函数,但出现以下错误:
回溯(最近一次调用最后):文件“D:/faxstuff/3.godina/kvantna/plotgamma.py”,第 13 行,y1 = f1(x) 文件“D:/faxstuff/3.godina/ kvantna/plotgamma.py”,第 9 行,在 f1 返回 gamma(x) 文件“mtrand.pyx”,第 1599 行,在 mtrand.RandomState.gamma (numpy\random\mtrand\mtrand.c:8389) ValueError: shape
怎么做?这应该很容易,但我似乎失败了:(
【问题讨论】:
-
请发布确切的错误信息。
-
Traceback (most recent call last): File "D:/faxstuff/3.godina/kvantna/plotgamma.py", line 13, in <module> y1 = f1(x) File "D:/faxstuff/3.godina/kvantna/plotgamma.py", line 9, in f1 return gamma(x) File "mtrand.pyx", line 1599, in mtrand.RandomState.gamma (numpy\random\mtrand\mtrand.c:8389) ValueError: shape <= 0 -
这是一个很好的例子说明为什么不推荐
import *。
标签: python plot scipy matplotlib