问题描述
我正在尝试检查以下Python代码中调用的函数 LinearNDInterpolator
from scipy.interpolate.interpnd import LinearNDInterpolator
我想运行一个Python脚本调用函数 LinearNDInterpolator
并在例如
所以我自己对此进行了测试。
找到site-packages文件夹以找到scipy源文件
在Powershell中
python -m网站
对我来说文件夹为
C:\Program Files(x86)\Python37-32\Lib\site-packages\scipy
打开 init .py文件并设置您的bre代码第一行上的ak点
__ all__ = ['test']<-那里的断点
运行>调试>进入我的代码
I am trying to examine the function LinearNDInterpolator
invoked in the following Python code
from scipy.interpolate.interpnd import LinearNDInterpolator
I would like to run a Python script invoking function LinearNDInterpolator
and set a breakpoint at, say, line 304 of function LinearNDInterpolator
. How can I do this?
I am using PyCharm. I am not able to "step into" the code of LinearNDInterpolator
. The following is an example script I am running.
import numpy as np
from scipy.interpolate.interpnd import LinearNDInterpolator
import matplotlib.pyplot as plt
x = np.linspace(-1,1,100)
y = np.linspace(-1,1,100)
X, Y = np.meshgrid(x,y)
def f(x, y):
s = np.hypot(x, y)
phi = np.arctan2(y, x)
tau = s + s*(1-s)/5 * np.sin(6*phi)
return 5*(1-tau) + tau
T = f(X, Y)
# Choose npts random point from the discrete domain of our model function
npts = 400
px, py = np.random.choice(x, npts), np.random.choice(y, npts)
fig, ax = plt.subplots(nrows=2, ncols=2)
# Plot the model function and the randomly selected sample points
ax[0,0].contourf(X, Y, T)
ax[0,0].scatter(px, py, c='k', alpha=0.2, marker='.')
ax[0,0].set_title('Sample points on f(X,Y)')
# Interpolate using three different methods and plot
i = 0
method = 'linear'
#for i, method in enumerate(('nearest', 'linear', 'cubic')):
ip = LinearNDInterpolator((px, py), f(px,py))
Ti = ip((X, Y))
r, c = (i+1) // 2, (i+1) % 2
ax[r,c].contourf(X, Y, Ti)
ax[r,c].set_title('method = {}'.format(method))
plt.show()
EDIT - Sample code works for me minus commented out line that was in error
So I tested this myself.
Find the site-packages folder to find the scipy source files
In powershell
python -m site
For me this folder wasC:\Program Files (x86)\Python37-32\Lib\site-packages\scipy
open the init.py file in pycharm and set your break point on the first line of code
__all__ = ['test'] <- breakpoint there
Run > Debug > Step Into My Code
这篇关于在PyCharm中,如何在导入的Cython扩展代码中的行处断开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!