我正在为二进制发行版中包含NumPy的应用程序编写插件,但不是SciPy.我的插件需要将数据从一个常规3D网格插入另一个常规3D网格.从源代码运行,这可以非常有效地使用,scipy.ndimage或者,如果用户没有安装SciPy,.pyd我编写了一个编织的编织.不幸的是,如果用户正在运行二进制文件,那么这两个选项都不可用.
我在python中编写了一个简单的三线性插值例程,它给出了正确的结果,但对于我正在使用的数组大小,需要很长时间(约5分钟).我想知道是否有办法只使用NumPy中的功能加快速度.就像scipy.ndimage.map_coordinates,它需要一个3D输入数组和一个数组,每个点的x,y和z坐标都要进行插值.
def trilinear_interp(input_array, indices):
"""Evaluate the input_array data at the indices given"""
output = np.empty(indices[0].shape)
x_indices = indices[0]
y_indices = indices[1]
z_indices = indices[2]
for i in np.ndindex(x_indices.shape):
x0 = np.floor(x_indices[i])
y0 = np.floor(y_indices[i])
z0 = np.floor(z_indices[i])
x1 = x0 + 1
y1 = y0 + 1
z1 = z0 + 1
#Check if xyz1 is beyond array boundary:
if x1 == input_array.shape[0]:
x1 = x0
if y1 == input_array.shape[1]:
y1 …Run Code Online (Sandbox Code Playgroud) 我是一个新手,所以要善良;-)
我有一个使用PyQt4和python 2.6制作的GUI,带有一个工作文件对话框(即你点击了一个按钮,弹出一个窗口,允许你选择要加载/保存的文件).GUI的代码就像2000行,所以我将包括我认为重要的位:
from PyQt4 import QtGui as qt
from PyQt4 import QtCore as qc
class NuclearMotion(qt.QWidget):
def __init__(self, parent=None):
super(NuclearMotion, self).__init__(parent)
file_button = qt.QPushButton("Use data from file")
mainLayout = qt.QGridLayout()
mainLayout.addWidget(file_button, 14, 8, 1, 2)
def choose_file():
file_name = qt.QFileDialog.getOpenFileName(self, "Open Data File", "", "CSV data files (*.csv)")
self.connect(file_button, qc.SIGNAL("clicked()"), choose_file)
self.setLayout(mainLayout)
if __name__ == '__main__':
import sys
app = qt.QApplication(sys.argv)
NuclearMotionWidget = NuclearMotion()
NuclearMotionWidget.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
以上工作绝对没问题.我使用各种教程手动输入了所有代码.我现在使用QT设计器和pyuic4创建了一个新的GUI,将其转换为.py文件.现在我无法使文件对话框工作.以下代码导致类型错误:
from PyQt4 import QtCore, QtGui
class Ui_mainLayout(object):
def setupUi(self, mainLayout):
mainLayout.setObjectName(_fromUtf8("mainLayout"))
mainLayout.resize(598, …Run Code Online (Sandbox Code Playgroud)