Python 和 JMP 18你好,
我正在尝试在 JMP 18 中使用一段代码,但我不确定我是否理解它的工作原理。我一开始就安装了 pythonn 包,然后将变量发送到 Python 并运行 Python 代码。但我总是收到以下错误之一:要么它无法检测到 numpy(即使安装了 numpy),要么它不再检测到我刚刚发送的变量。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
lstMeasures = Column( dt, "height" ) << Get As Matrix();
Python Install Packages( "numpy pandas scipy" );
Python Send( lstMeasures );
Python Submit(
"
import numpy as np
from scipy.stats import kstest, norm, weibull_min, rayleigh
data = np.array(lstMeasures)
# Fit des lois
mu, sigma = norm.fit(data)
ks_norm = kstest(data, 'norm', args=(mu, sigma))
c, loc, scale = weibull_min.fit(data)
ks_weibull = kstest(data, 'weibull_min', args=(c, loc, scale))
loc_r, scale_r = rayleigh.fit(data)
ks_rayleigh = kstest(data, 'rayleigh', args=(loc_r, scale_r))
"
);
ks_norm = Python Get( ks_norm );
ks_weibull = Python Get( ks_weibull );
ks_rayleigh = Python Get( ks_rayleigh );


自动化和脚本回复:Python 和 JMP 18您是否在 JMP(JSL)脚本编辑器中运行了该代码?我暂时没发现该脚本有什么问题,它对我来说运行良好。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
lstMeasures = Column(dt, "height") << Get As Matrix();
Python Install Packages("numpy pandas scipy");
Python Send(lstMeasures);
Python Submit("
import numpy as np
from scipy.stats import kstest, norm, weibull_min, rayleigh
data = np.array(lstMeasures)
mu, sigma = norm.fit(data)
ks_norm = kstest(data, 'norm', args=(mu, sigma))
c, loc, scale = weibull_min.fit(data)
ks_weibull = kstest(data, 'weibull_min', args=(c, loc, scale))
loc_r, scale_r = rayleigh.fit(data)
ks_rayleigh = kstest(data, 'rayleigh', args=(loc_r, scale_r))
");
ks_norm = Python Get(ks_norm);
ks_weibull = Python Get(ks_weibull);
ks_rayleigh = Python Get(ks_rayleigh);
show(ks_norm, ks_weibull, ks_rayleigh);
@Paul_Nelson
回复:Python 和 JMP 18您好,我之前使用的是 JMP 18.0.0,但我重新启动了 JMP,现在不再出现问题了……
回复:Python 和 JMP 18有时,尤其是第一次运行 JMP 时,您可能需要重新启动 JMP 才能识别新安装的 Python 包。Numpy 特别挑剔。此外,Python 的包处理机制不会重新查找导入失败的包。它知道导入失败了,所以为什么要重试呢?您可以使用 importlib 和 reload 强制重新加载包。