所以我想繪製簡單的伽馬函數,但我有一些問題。我的代碼是:Python中的伽馬函數圖
#!/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()
我試圖從數學進口伽瑪功能,並從scipy.special但我得到以下錯誤:
Traceback (most recent call last): File "D:/faxstuff/3.godina/kvantna/plotgamma.py", line 13, in 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
怎麼辦呢?這應該很容易,但我似乎失敗:(
請後確切的錯誤消息 – 2011-04-16 09:34:54
'回溯(最近最後一次通話): 文件「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,in mtrand.RandomState.gamma(numpy \ random \ mtrand \ mtrand.c:8389) ValueError:shape <= 0' –
2011-04-16 10:30:30
這是不推薦使用'import *'的原因。 – OldGeeksGuide 2016-11-24 00:36:15